Opening more than 9 sessions with Selenium

放肆的年华 提交于 2019-12-11 05:17:47

问题


I am trying to use Selenium to visit a website with a few dozen sessions at a time, but whenever I try and setup more than 9 sessions, it says "chromedriver.exe is not responding" and the sessions start closing themselves.

Here is my code:

from selenium import webdriver
import time

url = "website URL"
amount = 36

def generateBrowsers():
    for x in range(0, amount):
        driver = webdriver.Chrome(executable_path="C:/Users/user/Documents/chromedriver_win32/chromedriver.exe")
        driver.get(url)
        time.sleep(3)

generateBrowsers()

Does anyone know what could be wrong?


回答1:


Logically, your code block have No Errors.

But as you are trying to open 36 Sessions at a time you need to consider the following facts :

  • Each call to driver = webdriver.Chrome(executable_path="C:/Users/user/Documents/chromedriver_win32/chromedriver.exe") will initiate :

    1. A new WebDriver instance
    2. A new Web Browser instance
    
  • Each of the WebDriver instance and Web Browser instance will need to occupy some amount of :

    1. CPU
    2. Memory
    3. Network
    4. Cache
    

Now, as you execute your Test Suite from your system which also runs a lot other Applications (some of them may be on Start Up) tries to accomodate within the available CPU, Memory, Network or Cache. So whenever, the usage of mentioned parameters gets beyond the threshhold level, either the next new chromedriver.exe or the chrome.exe will be unable to spawn out properly. In your case chromedriver.exe was unable to spawn out. Hence you see the error :

chromedriver.exe is not responding

Solution

If you have a requirement of spawning 36 Sessions at a time you need to use :

  • Selenium in Grid Configuration : Selenium Grid consists of a Hub and Node and you will be able to distribute required number of sessions among number of Nodes.


来源:https://stackoverflow.com/questions/48045663/opening-more-than-9-sessions-with-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!