1

我正在尝试使用 Selenium 加载页面进行测试,但我不断收到此 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 错误。现在我尝试了许多不同的方法来允许它,但它根本行不通!

WebDriver driver = new HtmlUnitDriver(){
            protected WebClient modifyWebClient(WebClient client){
                try {                   
                    client = new WebClient(BrowserVersion.FIREFOX_3_6);
                    client.setUseInsecureSSL(true);
                    client.setUseInsecureSSL(true);
                    client.setThrowExceptionOnScriptError( false );
                    client.setPrintContentOnFailingStatusCode( true );
                    client.setThrowExceptionOnFailingStatusCode( true );
                    client.setCssEnabled( true );
                    client.setJavaScriptEnabled( true );
                    XTrustProvider.install(); // Allow all certs
                    SSLUtilities.trustAllHostnames();// to turn off the default hostname verification on HTTPS connection;
                    SSLUtilities.trustAllHttpsCertificates();// to turn off the default certificate validation on HTTPS 
                } catch (GeneralSecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                 return client;
               }
            } ;

有人有建议吗?

4

1 回答 1

1

我已经想通了。这似乎是 HtmlUnit 中的一个错误,当前可用的 2.9 版本于 2011 年发布。我从源代码构建它,现在它可以工作了!

于 2012-07-17T14:58:49.930 回答