2

I'm trying to use the HTMLUnit WebDriver from Python with the following code:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver

if __name__ == '__main__':
    webdriver = WebDriver('http://127.0.0.1:4444/wd/hub', DesiredCapabilities.HTMLUNIT)
    webdriver.get('http://www.google.com')

... and get the following error:

Traceback (most recent call last):
  File "bcc_mon_webdriver.py", line 8, in <module>
    webdriver = WebDriver('http://127.0.0.1:4444/wd/hub', DesiredCapabilities.HTMLUNIT)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 63, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 105, in start_session
    'desiredCapabilities': desired_capabilities,
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in execute
    self.error_handler.check_response(response)
  File "c:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 147, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'Error forwarding the new session cannot find : {platform=ANY, browserName=htmlunit, version=}' ; Stacktrace: Method process threw an error in RequestHandler.java 

I use selenium-server-standalone-2.25.0.jar with the Python selenium module also in version 2.25. The Selenium server is running on localhost and it works fine with e.g. DesiredCapabilities.FIREFOX.

Do I have to install htmlunit manually? The selenium websites says that the standalone-jar contains all dependencies.

1 Answer 1

2

The problem is you don't have a node that matches the {platform=ANY, browserName=htmlunit, version=} pattern. To fix it you need to start a selenium node with those browser settings, like this:

java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=htmlunit

On the Selenium wiki ( http://code.google.com/p/selenium/wiki/Grid2 ) it says:

"By default, this starts 11 browsers : 5 Firefox, 5 Chrome, 1 Internet Explorer."

So to be able to use different browsers - like htmlunit - you'll have to start nodes with -browser parameter, check desired_capabilities.py file (located in your selenium egg under selenium/webdriver/common/) for a reference of which parameters are required for each browser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.