java - selenium webdriver 异常(在 Firefox 中)

标签 java selenium selenium-webdriver

我使用selenium firefox驱动程序3.3.1,selenium java 3.3.0,gecko驱动程序0.14和firefox 52。当我运行我的代码时,出现“您的连接不安全”页面,但是当我手动打开它时,它将打开而无需任何错误 这是我收到的错误消息

Exception in thread "main" org.openqa.selenium.WebDriverException: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604) at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325) at automation.Qwik_events_uat_firefox.main(Qwik_events_uat_firefox.java:24)

最佳答案

根据geckodriver

acceptInsecureCerts
Boolean initially set to false, indicating the session will not implicitly trust untrusted or self-signed TLS certificates on navigation.

您可以像下面这样初始化您的 FirefoxDriver 以避免出现此问题

    FirefoxProfile ff = new FirefoxProfile();
    ff.setAcceptUntrustedCertificates(true);
    WebDriver driver = new FirefoxDriver(ff);

或者您可以使用 DesiredCapability,例如

    DesiredCapabilities caps = DesiredCapabilities.firefox();
    caps.setCapability("acceptInsecureCerts", true);
    WebDriver driver = new FirefoxDriver(caps);

您还应该使用 GeckoDriver 0.15 因为 selenium 建议这样做

根据Selenium Changelog

v3.3.1

  • Better support for geckodriver v0.15.0. Notably, exceptions returned from the remote end are now unwrapped properly.

关于java - selenium webdriver 异常(在 Firefox 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42808561/

相关文章:

java - 在没有成员变量的情况下通过实现创建抽象类有什么意义?

java - gwt 不支持初始化 vector

java - 如何在 java 中用 while 循环叠加数字模式?

Java cucumber : Take @CucumberOptions from external source like a property file

java - 无法在 selenium 代码中使用 poi 在 excel 文件中写入输出

java - Java中通过jdbf读取DBF时最后一条记录读取了两次

java - 如何在多个浏览器中使用不同的登录并行执行 TestNG.xml

python - 如何在 Python 中将 while True 更改为 while False?

java - 在 selenium 的表中断言多个值

java - 使用动态 Id 说明构建 xpath 表达式 - 带有 java 的 webdriver