gpt4 book ai didi

java - 如何在selenium中通过browsermob-proxy处理Edge浏览器的SSL证书

转载 作者:行者123 更新时间:2023-12-01 18:17:54 25 4
gpt4 key购买 nike

我想在所有浏览器上自动化 Web 应用程序。我的代码在 chrome、firefox 上运行良好,但当我在 Edge 上尝试时,它显示 ssl 证书错误。我该如何处理这个问题。尝试了很多解决方法但未能实现。

if((browser.equalsIgnoreCase("Edge"))){

            //browserName = "";
browser = "Edge";

//set path to Edge.exe
System.setProperty("webdriver.edge.driver","C:\\edgedriver.exe");
if(enableProxy == true) {
proxy = new ProxyServer();
proxy.setTrustAllServers(true);

proxy.start();
System.out.println( proxy.getPort());
Proxy seleniumProxy = new Proxy();
EdgeOptions options = new EdgeOptions();
String hostIp = Inet4Address.getLocalHost().getHostAddress();
seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());

seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
options.setProxy(seleniumProxy);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

//DesiredCapability 功能 = new DesiredCapability();//capability.setCapability(CapabilityType.PROXY, proxy);

                proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

proxy.newHar();
driver = new EdgeDriver(EdgeDriverService.createDefaultService(),options);


//driver = new EdgeDriver(capabilities);
driver.manage().window().maximize();
}else {

//create Edge instance
driver = new EdgeDriver();
driver.manage().window().maximize();
}
}

最佳答案

您可以在 DesiredCapability 中将 ACCEPT_SSL_CERTS 设置为 true:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

System.setProperty("webdriver.edge.driver", "C://EdgeDriver.exe");
WebDriver driver = new EdgeDriver(capabilities);

关于java - 如何在selenium中通过browsermob-proxy处理Edge浏览器的SSL证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60332645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com