我使用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)
最佳答案
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 建议这样做
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/