1
votes

I am using Selenium Webdriver, 2.25 I have a local hub set up with this json setting for chrome and firefox:

[
    {
        "browserName": "firefox",
        "maxInstances": 5,
        "seleniumProtocol": "WebDriver"
    },
    {
        "browserName": "chrome",
        "maxInstances": 5,
        "seleniumProtocol": "WebDriver"
    }
],

I can start a webdriver firefox session like this:

capability = getattr(webdriver.DesiredCapabilities, "FIREFOX")
dd=webdriver.Remote('http://localhost:4444/wd/hub', capability)

which works fine but if I try to start a Chrome session like this:

capability = getattr(webdriver.DesiredCapabilities, "CHROME")
dd=webdriver.Remote('http://localhost:4444/wd/hub', capability)

I get this error:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 62, in init self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 104, in start_session 'desiredCapabilities': desired_capabilities, File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 155, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 147, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: None ; Stacktrace: Method innerGet threw an error in None

But I can start a direct connection to Chrome like this:

dd=webdriver.Chrome()

Without any problem.

What can I do to get to Chrome through my Selenium Hub?

2

2 Answers

1
votes

You need to setup the chrome driver, info about that here

UPDATE


Based on a sample json setup file and steps provided in the first link, seems like the browser name should not be in Upper but in fact lower case.

So change CHROME to chrome

Example

WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome());
driver.get("http://www.google.com");

and in your case, I would assume

dd=webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.chrome())
2
votes

I had EXACTLY the same problem.

The thing is, unlike Firefox, Chrome needs separate chromdriver.exe to act as bridge between browser and driver.

From the documentation:

The ChromeDriver consists of three separate pieces. There is the browser itself ("chrome"), the language bindings provided by the Selenium project ("the driver") and an executable downloaded from the Chromium project which acts as a bridge between "chrome" and the "driver". This executable is called "chromedriver", but we'll try and refer to it as the "server" in this page to reduce confusion.

Download chromdriver.exe here

And put it in your chrome binary dir.

I then use a .bat file to launch my hub with this listing:

java -Dwebdriver.chrome.driver="C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" -jar D:\soft\selenium-server-standalone-2.29.0.jar

I then execute the following Python code on my Linux box, it worked flawlessly once I put chromedriver.exe in the Chrome dir and launched the hub with correct path parameters:

from selenium import webdriver
url = "http://192.168.1.115:4444/wd/hub"
driver = webdriver.Remote(command_executor = url, desired_capabilities = {'browserName':'chrome'})
driver.get("http://google.com")

Hope this helps you and the others with the same problem. Finding the solution was of course not to take firefox approach for granted and RTFM: Chrome driver documentation