javax.net.ssl.SSLException:收到致命警报:带有 Selenium 的协议版本

Posted

技术标签:

【中文标题】javax.net.ssl.SSLException:收到致命警报:带有 Selenium 的协议版本【英文标题】:javax.net.ssl.SSLException: Received fatal alert: protocol_version with Selenium 【发布时间】:2016-04-18 03:15:18 【问题描述】:

运行 selenium 脚本时收到此错误

org.openqa.selenium.WebDriverException:javax.net.ssl.SSLException:收到致命警报:protocol_version

下面的堆栈跟踪:

驱动信息:driver.version: htmlUnitDriver 在 sun.security.ssl.Alerts.getSSLException(Alerts.java:208) 在 sun.security.ssl.Alerts.getSSLException(Alerts.java:154) 在 sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979) 在 sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086) 在 sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) 在 sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) 在 sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) 在 org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) 在 org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) 在 com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.connectSocket(HtmlUnitSSLConnectionSocketFactory.java:189) 在 org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) 在 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) 在 org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) 在 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) 在 org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) 在 org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) 在 org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) 在 org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) 在 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71) 在 com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:179) 在 com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1321) 在 com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1238) 在 com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:346) 在 com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:415) 在 org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:541) 在 org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:530) 在 com.mimos.performance.PerfTest.PerfTest(PerfTest.java:34)

构建信息:版本:'2.48.2',修订:'41bccdd10cf2c0560f637404c2d96164b67d9d67',时间:'2015-10-09 13:08:06'

java 版本“1.7.0_79” Java(TM) SE 运行时环境 (build 1.7.0_79-b15) Java HotSpot(TM) 64 位服务器 VM(内部版本 24.79-b02,混合模式)

    HtmlUnitDriver driver = new HtmlUnitDriver();        
    driver.get(url);
    WebElement passwordLogo = driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div/ul/li/a"));
    passwordLogo.click();
    WebElement userID = driver.findElement(By.xpath("/html/body/div/form[1]/input[1]"));
    userID.sendKeys(username);
    WebElement next = driver.findElement(By.xpath("/html/body/div/form[1]/input[2]"));
    next.click();
    WebElement password =  driver.findElement(By.xpath("/html/body/div/form[1]/div/input[1]"));
    password.sendKeys(password);
    WebElement login = driver.findElement(By.xpath("/html/body/div/form[1]/div/input[3]"));
    login.click();
    System.out.println(driver.getTitle());

【问题讨论】:

【参考方案1】:

早上好。可能与 javax.net.ssl.SSLException: Received fatal alert: protocol_version有关

这似乎是协议版本不匹配,此异常通常发生在客户端和服务器使用的 SSL 协议版本不匹配时。您的客户端应使用服务器支持的协议版本。

【讨论】:

不知道如何或为什么,设法通过将我的 jdk 升级到 8 来克服这个问题

以上是关于javax.net.ssl.SSLException:收到致命警报:带有 Selenium 的协议版本的主要内容,如果未能解决你的问题,请参考以下文章