简体   繁体   中英

WebDriverException on invoking webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.CHROME) through Selenium and Python

I'm pretty sure this'll be a head smacker, but I've followed ever bit of doc I can find and I can't get rid of this error. I'm in the process of setting up a Selenium Grid (in Docker) and can get tests to run only if I don't specify the remote. Here's the code

def setUp(self):
    self.browser = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.CHROME)

FWIW, this works fine, but isn't useful in a grid environment without the command_executor:

def setUp(self):
    self.browser = webdriver.Chrome()

Based on a number of sources, including https://hackr.io/blog/complete-guide-selenium-webdriver , the call to the RemoteWebDriver should be correct.

Here's the error:

ERROR: test_hackernews_search_for_selenium (__main__.HackerNewsSearchTest)
Traceback (most recent call last):
  File "test.py", line 16, in setUp
    self.browser = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.CHROME)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: None

This error message...

ERROR: test_hackernews_search_for_selenium (__main__.HackerNewsSearchTest)
Traceback (most recent call last):
  File "test.py", line 16, in setUp
    self.browser = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.CHROME)
.
WebDriverException: Message: None

...implies that the client program was unable to initiate a new WebBrowsing Session ie Chrome Browser session.

Your main issue is the connectivity between the Selenium Grid Hub and Selenium Grid Node .


Solution

Ensure the following:

  • The Selenium Grid Hub is initiated successfully.
  • The Selenium Grid Node is initiated and provisioned successfully within the Selenium Grid Hub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM