Selenium Webdriver 如何处理 Edge 中的 SSL 证书?
我们可以使用Seleniumwebdriver在Edge浏览器中处理SSL证书。这是在EdgeOptions类的帮助下完成的。我们将创建此类的一个对象并将参数setAcceptInsecureCerts设置为true值。
最后,必须将此信息传递给webdriver对象以获得所需的浏览器设置。SSL是一种旨在在服务器和浏览器之间建立安全连接的协议。
语法
EdgeOptions e = new EdgeOptions(); e.setAcceptInsecureCerts(true);
代码实现
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class EdgeBrwserSSL{
public static void main(String[] args) {
System.setProperty("webdriver.edge.driver",
"C:\\Users\\ghs6kor\\Desktop\\Java\\msedgedriver.exe");
//EdgeOptions的实例
EdgeOptions e = new EdgeOptions();
//将setAcceptInsecureCerts配置为true布尔值
e.setAcceptInsecureCerts(true);
//EdgeDriver的对象
WebDriver driver = new EdgeDriver(e);
//隐式等待
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//网址启动
driver.get("application url");
}
}