Search code examples
pythonhtmlunit

Selenium server unable to create session with HTMLUnit


I have started a local selenium server, and got it working with Chrome, but for some reason I cant get it working with HTMLUnit (which I need because chrome is too heavy for the load I intend to run).

I launch selenium server like this:

java -jar selenium-server-standalone-3.141.59.jar

But I've also tried this (as I'm not really sure how the dependency to htmlunit driver is supposed to work). Either way, both give the same result:

java -cp selenium-server-standalone-3.141.59.jar:htmlunit-driver-2.33.3-jar-with-dependencies.jar org.openqa.grid.selenium.GridLauncherV3

I use the python bindings:

self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.HTMLUNITWITHJS)

The error I get is:

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "htmlunit",
    "javascriptEnabled": true,
    "version": "firefox",
    "platform": "ANY"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "htmlunit"
      },
      {
        "browserName": "htmlunit",
        "browserVersion": "firefox",
        "platformName": "any"
      }
    ]
  }
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: '...', ip: 'fe80:0:0:0:1ce9:33:4280:d3bd%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '11.0.1'
Driver info: driver.version: unknown
Stacktrace:
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4 (NewSessionPipeline.java:76)
    at java.util.Optional.orElseThrow (Optional.java:408)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5 (NewSessionPipeline.java:75)
    at java.util.Optional.orElseGet (Optional.java:369)
    at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:73)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:834)

Solution

  • I was so close... All I had to do was reverse the class path order.

    java -cp htmlunit-driver-2.33.3-jar-with-dependencies.jar:selenium-server-standalone-3.141.59.jar org.openqa.grid.selenium.GridLauncherV3