Selenium 2 Webdriver and IE 9 Security Certificate
Asked Answered
P

8

22

I have some Selenium 2 Webdriver test cases for Firefox and Internet Explorer 9. When I access https URLs on IE9 (Windows 7 64bit) I get "There is a problem with this website's security certificate". At this point the test hangs and eventually fails. I tried:

  • Getting Selenium to click on the "Continue to this website (not recommended)." link. This can't be done as this error page is not your usual page. Same with JavaScript - it doesn't execute.
  • I tried adding the registry key
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_ERROR_PAGE_BYPASS_ZONE_CHECK_FOR_HTTPS_KB954312
    that prevents the certificate-error-page from displaying - didn't work. Probably because I'm on Windows 7 with IE9.
  • Following this advice I tried using browsermob proxy, but there's very little documentation out there and I couldn't work it out.
  • Finally, I don't have admin access to my PC - e.g. no access to group policies. Selenium 2 Webdriver works fine on Firefox. I have all security zones enabled in IE Internet Options and if I run the tests on other URLs (http) then there is no problem.

    Has anyone got a solution to this problem? Does anyone now hot to use browsermob proxy (or any other proxy) effectively to overcome this issue?

    Thanks, Damo

    Polyhydric answered 10/10, 2011 at 9:9 Comment(1)
    The Feature key you mentioned had nothing to do with HTTPS certificate acceptance. Your best bet is to install the certificate in the user's Trusted store (certmgr.msc) assuming that the error is that the root isn't trusted.Victim
    P
    3

    I found the answer on the SQA board: https://sqa.stackexchange.com/questions/1928/selenium-2-webdriver-and-ie-9-security-certificate

    We created a certificate and it It worked like a charm.

    Polyhydric answered 28/11, 2011 at 16:47 Comment(1)
    I even had a certificate still the behaviour of IE was random ... but Nyegaard's Solution worked also ....Marc
    P
    26

    Okay I just got it working under IE9 using C# and the following code:

    IWebDriver driver = new InternetExplorerDriver();
    driver.Url(YOUR_URL);
    driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");
    

    And now it will go to the intended page. For Java it's as simple as:

    WebDriver driver = new InternetExplorerDriver();
    driver.get(YOUR_URL);
    driver.get("javascript:document.getElementById('overridelink').click();");
    
    Phineas answered 20/7, 2012 at 10:14 Comment(2)
    Worked .... cool man ... the thing is this ... people copy ur code at all the places :DMarc
    I actually used to simply perform a findElement(By.id("overridelink")) and it would work for IE11, but for some reason it cannot find the element for IE9. The element is named exactly the same, i can inspect it with IE Dev tool. NO idea why selenium fails to find it through webdriver.findElement, but your javascript version seems to work. Thanks!Tieshatieup
    C
    4

    Using the Selenium-Python bindings:

    #region SSL workaround for IE
    if "Certificate Error" in driver.title:
        driver.get("javascript:document.getElementById('overridelink').click();")
    
    Chablis answered 2/9, 2014 at 19:47 Comment(0)
    P
    3

    I found the answer on the SQA board: https://sqa.stackexchange.com/questions/1928/selenium-2-webdriver-and-ie-9-security-certificate

    We created a certificate and it It worked like a charm.

    Polyhydric answered 28/11, 2011 at 16:47 Comment(1)
    I even had a certificate still the behaviour of IE was random ... but Nyegaard's Solution worked also ....Marc
    S
    2

    This worked for me in the past, give it a try,

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);      
    Webdriver driver = new InternetExplorerDriver(capabilities);
    
    Semitrailer answered 12/10, 2011 at 2:6 Comment(3)
    Tried it, but with no luck. Did you try this in IE9?Polyhydric
    I haven't tried it on IE9. Does non-admin privileges allow you to install the security certificate in IE? or that's something you don't prefer?Semitrailer
    The latest version does not include a override that accepts a DesiredCapabilities parameter?Totalizer
    B
    0

    Any progess in this? I'm trying to do this capabilities thing... but I don't know how to do it using Ruby :(

    In chrome it is simple since you can use switches:

    nav=Selenium::WebDriver.for(:chrome, :switches => %w[--ignore-certificate-errors -])
    

    Maybe it is possible to do it for IE using switches

    Bandolier answered 21/10, 2011 at 14:44 Comment(0)
    G
    0

    there is a much simpler solution in case you use IE driver, documented in this reply. The added benefit is that you don't have to be the site owner and you don't have to tangle with browsermob or the registry or any other low-level technology

    Germann answered 1/10, 2013 at 13:46 Comment(0)
    S
    0

    We can use the the following code.

    wait =new WebDriverWait(webdriver, 10);
    
    webdriver.get(url);
    WebElement ele =wait.until(ExpectedConditions.elementToBeClickable(
                   webdriver.findElement(By.linkText("Continue to this website (not  
                   recommended)."))));
     ele.click();
    
    Sixtieth answered 19/8, 2014 at 10:13 Comment(0)
    B
    0

    The other answers have the correct idea, but fail in practice because the WebDriver doesn't navigate immediately to the certificate error page. The correct implementation should wait a bit.

    new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("Certificate"));
    
    
    driver.navigate().to("javascript:document.getElementById('overridelink').click()");
    
    Baneberry answered 13/6, 2016 at 17:29 Comment(0)

    © 2022 - 2024 — McMap. All rights reserved.