Home » Java » java – How to handle the SSL certificate of Edge browser via browsermob-proxy in selenium-Exceptionshub

java – How to handle the SSL certificate of Edge browser via browsermob-proxy in selenium-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want to automate the web application on all browsers.My code is running fine for chrome,firefox but when i tried it on Edge,it showing the ssl certificate error.
how i can handle this.tried so many workarounds but failed to achieve it.

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);

// DesiredCapabilities capabilities = new DesiredCapabilities();
// capabilities.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();
            }
        }
How to&Answers:

You can set ACCEPT_SSL_CERTS to true in DesiredCapabilities:

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

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