3
votes

We've probably all seen this screen when testing, all you need is a HTTPS site with a self signed cert and you get the "There is a problem with this website's security certificate" screen, which requires you to click a link to continue.

With Watir this is no problem, I automate the screen as I would any other webpage, clicking the link according to its text or ID value.

With Watir-Webdriver it's as if nothing inside the HTML can be recognized. and I'm not alone in this See this question

It's not just trying to click a link, nearly anything you try here will fail on this page Even a simple function such as puts browser.text will return an error.

Selenium::WebDriver::Error::NoSuchElementError: Unable to find element with tag name == body

You can view source, use developer tools, or have the browser element spit out it's HTML and plainly see the darned body tag right there, but Webdriver is blind to it for some reason.

I don't know if it is a clue or a red-herring, but I know webdriver uses a ton of XPATH under the hood, and I believe XPATH is case sensitive. and in that regard I see something very unusual when I use puts browser.html against this page, in that every single tag-name is in full upper-case. Somewhat unusual but legal valid HTML in any case. Using browser.html on other pages shows lower case tags. Could this be what is causing webdriver to have so much of a problem with this page?

Does anyone have any bright ideas as to how I might be able to get webdriver to see the link element so I can click it?

Output from the browser object when I ask it for the page HTML

irb(main):019:0> puts $browser.html  #note, indentation is added later for clarity
<HTML dir=ltr>
<HEAD>
<TITLE>Certificate Error: Navigation Blocked</TITLE>
<LINK rel=stylesheet type=text/css href="ErrorPageTemplate.css">
<META name=MS.LOCALE content=EN-US>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META content=Yes http-equiv=MSThemeCompatible>
<SCRIPT language=javascript type=text/javascript src="errorPageStrings.js">
</SCRIPT>
<SCRIPT language=javascript type=text/javascript src="httpErrorPagesScripts.js">
</SCRIPT>
<SCRIPT language=javascript type=text/javascript src="invalidcert.js">
</SCRIPT>
</HEAD>
<BODY onload="BodyLoad(); initMoreInfo('infoBlockID');" class=securityError>
<TABLE border=0 cellSpacing=0 cellPadding=0 width=730>
  <!-- Main title -->
  <TBODY>
  <TR>
    <TD id=shieldIconAlign vAlign=top rowSpan=3 width=60 align=left>
      <IMG id=shieldIcon alt="Shield icon" src="red_shield_48.png"> 
    </TD>
    <TD id=mainTitleAlign vAlign=middle align=left>
      <H1 id=mainTitle>There is a problem with this website's security certificate</H1>
    </TD>
  </TR>
  <TR>
    <TD>
      <H3>
        <DIV id=linkdiv name="linkdiv"></DIV>
      </H3>
    </TD>
  </TR>
  <TR>
  <!-- This row is for the the divider-->
    <TD id=errorCodeAlign class=errorCodeAndDivider align=right>&nbsp;
      <DIV class=divider></DIV>
    </TD>
  </TR>
  <!-- Error Body -->
  <TR>
    <TD></TD>
    <TD>
      <H3>
        <DIV style="DISPLAY: block" id=CertUnknownCA name="CertUnknownCA">
          The security certificate presented by this website was not issued by a trusted certificate authority.
        </DIV>
        <DIV style="DISPLAY: none" id=CertExpired name="CertExpired"></DIV>
        <DIV style="DISPLAY: none" id=CertCNMismatch name="CertCNMismatch"></DIV>
        <DIV style="DISPLAY: none" id=CertRevoked name="CertRevoked"></DIV>
        <NOSCRIPT id=securityCert1></NOSCRIPT><BR>
          <ID id=securityCert2>
            Security certificate problems may indicate an attempt to fool you or intercept any data you send to the server.
          </ID>
      </H3>
    </TD>
  </TR>
  <!-- Recommendation-->
  <TR>
    <TD>&nbsp;</TD>
    <TD><H2 id=recommendation><B>We recommend that you close this webpage and do not continue to this website. </B></H2></TD>
  </TR>
  <!-- close webpage-->
  <TR>
    <TD>&nbsp;</TD>
    <TD id=closeWebpageAlign vAlign=middle align=left>
      <H4 id=closeWebpage>
        <IMG class=actionIcon border=0 alt="Recommended icon" src="green_shield.png">
        <A href="javascript:closePage()">Click here to close this webpage.</A> 
      </H4>
    </TD>
  </TR>
  <!-- continue to site-->
  <TR>
    <TD>&nbsp;</TD>
    <TD id=continueToSiteAlign vAlign=middle align=left>
      <H4 id=continueToSite>
        <IMG id=ImgOverride class=actionIcon border=0 alt="Not recommended icon" src="red_shield.png">
        <A id=overridelink href="http://admanager.qa-prod.local/signups/lead_form" name=overridelink>Continue to this website (not recommended).</A> 
      </H4>
    </TD>
  </TR>
  <!-- InfoBlock -->
  <TR>
    <TD id=infoBlockAlign vAlign=top align=right>&nbsp; </TD>
    <TD id=moreInformationAlign vAlign=middle align=left>
      <H4>
        <TABLE>
          <TBODY>
            <TR>
              <TD vAlign=top>
                <A onclick="javascript:expandCollapse('infoBlockID', true); return false;" href="#">
                  <IMG id=infoBlockIDImage class=actionIcon border=0 alt="More information" src="down.png">
                </A>
              </TD>
              <TD vAlign=top>
                <SPAN id=moreInfoContainer>
                  <A href="javascript:expandCollapse('infoBlockID', true);">More information</A>
                </SPAN>
                <NOSCRIPT></NOSCRIPT>
              </TD>
            </TR>
          </TBODY>
        </TABLE>
      </H4>
      <DIV style="DISPLAY: none" id=infoBlockID class=infoBlock>
        <P>
        <LI id=errorExpl1>If you arrived at this page by clicking a link, check the website address in the address bar to be sure that it is the address you were expecting.
        <LI id=errorExpl2>When going to a website with an address such as https://example.com, try adding the 'www' to the address, https://www.example.com.
          <P></P>
          <P id=moreInfoSeeHelpPF>For more information, see "Certificate Errors" in Internet Explorer Help.
          </P>
        </LI>
      </DIV>
    </TD>
  </TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
=> nil
irb(main):020:0>
2
Have you tried adding the exception in IE beforehand? Maybe there's a setting in IE for less strict cert checking.m33lky
@M33lky, I suppose that might work as a workaround, but frankly since Watir has no problem clicking the link, I'd expect it to work in watir-webdriver also. And if this is broken I'd sure like to know why, since there seems to be nothing very special about the page source that I can see.Chuck van der Linden
Something funky might be happening when IE injects this warning that messes up webdriver internals..m33lky
it appears to disable javascript, which seems to be preventing webdriver from driving the browserChuck van der Linden

2 Answers

2
votes

I've done a bit of experimenting, including using the HTML I posted to create my own page, sans any JavaScript. If I work with that page, I find it blocks JavaScript actions. In that case, when I try to do things like browser.text, or browser.link.exists?, I see an IE warning popup that tells me that IE is preventing JS from working on that page. (something I never see on the actual cert error page) And in watir-webdriver I get the same errors that I reported. If I click the choice to allow JS, then I can work with the page in watir-webdriver.

So it appears something in in the very nature of the page is preventing any JS level automation which blocks Webdriver's access to the page.

I see why MS is doing this, they don't want a bogus site to somehow use JavaScript to get around that warning. Apparently the way Watir drives things (via OLE?) isn't seen as something you could do remotely and thus is allowed access to the page.

The solution then is to either use Watir for your IE automation, or make it so the certificate is trusted and thus you do not see the warning.

If you want to use Watir-Webdriver, then you need to add the certificates used on your test servers to the Trusted Root Certification Authorities store. Note NOT the default 'personal' store! When adding the cert, you need to change where it's going to put the cert or you are basically only doing a one time for that session authorization. There will be a warning that now all certificates from that authoritiy will be trusted. I would use this with great care, only on test systems, and only for trusting certs from your own internal test servers.

It's pretty easy to do this after manually proceeding to the page, via double-clicking the red warning reminding you the cert is invalid. If you've done that right, you can close the browser, re-open, do your navigation and not get an error.

2
votes
driver.goto("javascript:document.getElementById('overridelink').click()")