我对运行Selenium测试脚本并将HTML Unit用作浏览器/驱动程序很感兴趣。可以在Python中使用HTML吗?我尝试使用
driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS)
driver.get("google.com")
但我得到以下答复:
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)
谢谢!
答案 0 :(得分:1)
对于当前的堆栈跟踪,我认为问题出在您所使用的URL协议。使用-
driver.get("https://www.google.com")