2

我正在尝试使用 Selenium WebDriver 访问 HTTPS 网站。我想在不显示浏览器窗口的情况下执行此操作。

DesiredCapabilities capability = DesiredCapabilities.htmlUnit();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new HtmlUnitDriver(capability);
driver.get("https://en.wikipedia.org/wiki/HTTP_Secure"/);

我总是以这个错误告终:

Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:554)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:518)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:155)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1486)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1403)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:374)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:366)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:355)

我究竟做错了什么?

此外,正如 djangofan 在他的回答中所说,可以使用TrustEverythingSSLTrustManager. 如果是这样,怎么做?

4

1 回答 1

0

这是由于构建路径中有多个引用。我遇到了与上面提到的相同的问题。我参考了 http-client-4.1 和 selenium-rc.jar 我删除了 http-client、comms 和日志记录。然后它工作。

于 2013-08-27T12:41:59.147 回答