用htmlunit驱动程序设置python [英] set up python with htmlunit driver

查看:87
本文介绍了用htmlunit驱动程序设置python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ubuntu 18.04上使用selenium htmlunit驱动程序设置python.启动硒独立服务器

i am trying to set up python with selenium htmlunit driver on ubuntu 18.04. launching selenium standalone server

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

输出

00:00:46.177 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision:e82be7d358
00:00:46.299 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2020-05-25 00:00:46.366:INFO::main: Logging initialized @483ms to org.seleniumhq.jetty9.util.log.StdErrLog
00:00:46.685 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
00:00:46.811 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

然后在我的代码中,我尝试像这样连接到它

then in my code i am trying connect to it like this

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT
)

并出现错误

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "htmlunit",
    "version": null,
    "platform": null
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "htmlunit"
      }
    ]
  }
}

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:290)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5 (NewSessionPipeline.java:75)
    at java.util.Optional.orElseGet (Optional.java:267)
    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:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)

我浏览了整个互联网,发现设置 desired_capabilities 的各种不同形式,例如 {'platform':无,'browserName':'htmlunit','version':无} desired_capabilities = webdriver.DesiredCapabilities.HTMLUNITWITHJS 并启动这样的硒服务器 java -cp selenium-server-standalone-3.141.59.jar:htmlunit-driver-2.40.9-jar-with-dependencies.jar org.openqa.grid.selenium.GridLauncherV3 ,但这并没有帮助,并且错误是相同的.

i've looked across internet and found different variations of setting desired_capabilities like {'platform': None, 'browserName': 'htmlunit', 'version': None} or desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS and launching selenium server like this java -cp selenium-server-standalone-3.141.59.jar:htmlunit-driver-2.40.9-jar-with-dependencies.jar org.openqa.grid.selenium.GridLauncherV3 but this didnt help and the error is the same.

感谢您的帮助.

推荐答案

尝试一下:

import subprocess
from subprocess import PIPE, Popen
from selenium import webdriver

pid=Popen(['java','-cp','.\headless\htmlunit-driver-2.45.0-jar-with-dependencies.jar;.\headless\selenium-server-standalone-3.141.59.jar','org.openqa.grid.selenium.GridLauncherV3']).pid
print(pid)

driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT) #WITHJS)
driver.get('https://www.stackoverflow.com/')

print(driver.title)

print(driver.current_url)

这篇关于用htmlunit驱动程序设置python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆