简体   繁体   English

是否可以将 Python 中的 HTMLUnit 驱动程序与 Selenium 一起使用?

[英]Is it possible to use the HTMLUnit driver in Python with Selenium?

I'm interesting in running my Selenium test scripts and using HTML Unit as my browser/driver.我对运行我的 Selenium 测试脚本和使用 HTML Unit 作为我的浏览器/驱动程序很感兴趣。 Is it possible to use HTML with Python?是否可以在 Python 中使用 HTML? I tried using我尝试使用

driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS)
driver.get("google.com")

but I get the following response:但我得到以下回应:

Traceback (most recent call last):
  File ".\testtesttest.py", line 7, in <module>
    driver.get("google.com")
  File "C:\Users\slawi\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\slawi\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
    self.error_handler.check_response(response)
  File "C:\Users\slawi\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: java.net.MalformedURLException: no protocol: google.com
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'DESKTOP-16VCI25', ip: '192.168.139.1', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_101'
Driver info: driver.version: HtmlUnitDriver
Stacktrace:
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get (HtmlUnitDriver.java:667)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call (ChangeUrl.java:40)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call (ChangeUrl.java:25)
    at org.openqa.selenium.remote.server.handler.WebDriverHandler.handle (WebDriverHandler.java:41)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle (ResultConfig.java:113)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest (JsonHttpCommandHandler.java:186)
    at org.openqa.selenium.remote.server.InMemorySession.execute (InMemorySession.java:82)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$3 (WebDriverServlet.java:250)
    at java.util.concurrent.Executors$RunnableAdapter.call (None:-1)
    at java.util.concurrent.FutureTask.run (None:-1)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (None:-1)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (None:-1)
    at java.lang.Thread.run (None:-1)

Thanks!谢谢!

With the current stacktrace, I think the problem is with the URL protocol that you are using.使用当前的堆栈跟踪,我认为问题在于您使用的 URL 协议。 Use -用 -

driver.get("https://www.google.com")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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