1

我们如何使用 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();
}
4

2 回答 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()");   
于 2013-10-16T06:31:54.920 回答
0
WebDriver driver = new 'your Driver'();

driver.get("your app URL");
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
于 2017-10-03T11:04:39.503 回答