2013-07-01 127 views
2

我想使用Selenium WebDriver訪問HTTPS網站。我想這樣做,而不顯示瀏覽器窗口。使用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國在他的answer,它可以實現使用TrustEverythingSSLTrustManager。如果是這樣,怎麼樣?

回答

0

這是由於構建路徑中有多個引用。 我有上面提到的同樣的問題。 我引用了http-client-4.1和selenium-rc.jar 我刪除了http-client,comms和logging。然後它工作。

相關問題