如何在selenium Webdriver测试中处理chrome和Internet Explorer的SSL错误?

问题描述 投票:0回答:2

我们如何使用selenium web驱动程序处理chrome和Internet Explorer的SSL证书错误。当我使用Firefox时,它工作正常。能否请您提供处理SSL证书错误的解决方案。以下是我试过的代码。

// For Chrome
@Test
public void CRconfiguration() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\Selenium softwares\\drivers\\chromedriver.exe");
    _driver = new ChromeDriver(capabilities);
    System.setProperty("webdriver.chrome.driver",
            "D:/Softwares/Selenium softwares/drivers/chromedriver.exe");
    //_driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    login();
    _driver.close();
}


//For Internet Explorer
@Test
public void IEconfiguration() throws Exception {
    System.setProperty("webdriver.ie.driver",
    "D:/Softwares/Selenium softwares/drivers/IEDriverServer.exe");
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); 
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setJavascriptEnabled(true); 
    //capabilities.setCapability("chrome.switches", Arrays.asList("--ignore-certificate-errors"));
    _driver = new InternetExplorerDriver(capabilities);
    _driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    login();
    _driver.close();
}
google-chrome internet-explorer-8 selenium-webdriver junit4
2个回答
0
投票
For Chrome
System.setProperty("webdriver.chrome.driver","D:\\Selenium\\chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("https://www.flipkart.com/co");
driver1.navigate().to("javascript:document.getElementById('overridelink').click()");

For IE:
System.setProperty("webdriver.ie.driver", "D:\\Selenium\\IEDriverServer.exe");
WebDriver driver2 = new InternetExplorerDriver();
driver2.get("https://www.flipkart.com");
driver2.navigate().to("javascript:document.getElementById('overridelink').click()");   

0
投票
WebDriver driver = new 'your Driver'();

driver.get("your app URL");
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
© www.soinside.com 2019 - 2024. All rights reserved.