【问题标题】:How can we get Watir-Webdriver to work with the IE invalid cert screen?我们如何让 Watir-Webdriver 与 IE 无效证书屏幕一起工作?
【发布时间】:2012-05-15 03:50:19
【问题描述】:

我们可能都在测试时看到过这个屏幕,您所需要的只是一个带有自签名证书的 HTTPS 站点,然后您会看到“此网站的安全证书有问题”屏幕,这需要您单击一个链接继续。

使用 Watir 没问题,我可以像处理任何其他网页一样自动化屏幕,根据其文本或 ID 值单击链接。

使用 Watir-Webdriver 就好像 HTML 中的任何内容都无法识别。我并不孤单See this question

这不仅仅是试图点击一个链接,几乎你在这里尝试的任何东西都会在这个页面上失败即使是像puts browser.text这样的简单函数也会返回错误。

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

您可以查看源代码,使用开发者工具,或者让浏览器元素吐出它的 HTML 并在那里清楚地看到该死的 body 标签,但 Webdriver 出于某种原因对其视而不见。

我不知道这是一个线索还是一个红鲱鱼,但我知道 webdriver 在引擎盖下使用了大量的 XPATH,我相信 XPATH 是区分大小写的。在这方面,当我对这个页面使用puts browser.html 时,我看到了一些非常不寻常的东西,因为每个标签名都是完全大写的。无论如何,有点不寻常但合法有效的 HTML。在其他页面上使用 browser.html 会显示小写标签。这可能是导致 webdriver 对这个页面有这么多问题的原因吗?

对于如何让 webdriver 查看链接元素以便我可以单击它,是否有人有任何好主意?

当我向浏览器对象询问页面 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>

【问题讨论】:

  • 您是否尝试过事先在 IE 中添加异常?也许在 IE 中有一个设置不那么严格的证书检查。
  • @M33lky,我想这可能是一种解决方法,但坦率地说,由于 Watir 点击链接没有问题,我希望它也可以在 watir-webdriver 中工作。如果这被破坏了,我肯定想知道为什么,因为我可以看到的页面源似乎没有什么特别之处。
  • 当 IE 注入这个扰乱 webdriver 内部结构的警告时,可能会发生一些奇怪的事情。
  • 它似乎禁用了 javascript,这似乎阻止了 webdriver 驱动浏览器

标签: webdriver watir watir-webdriver


【解决方案1】:

我做了一些试验,包括使用我发布的 HTML 来创建我自己的页面,没有任何 JavaScript。如果我使用该页面,我发现它会阻止 JavaScript 操作。在这种情况下,当我尝试执行诸如 browser.text 或 browser.link.exists 之类的操作时,我会看到一个 IE 警告弹出窗口,告诉我 IE 正在阻止 JS 在该页面上工作。 (我从未在实际的证书错误页面上看到过)在 watir-webdriver 中,我得到了与我报告的相同的错误。如果我单击允许 JS 的选项,那么我可以使用 watir-webdriver 中的页面。

因此,页面的本质似乎是阻止任何阻止 Webdriver 访问页面的 JS 级别自动化。

我明白为什么 MS 会这样做,他们不希望虚假网站以某种方式使用 JavaScript 来绕过该警告。显然,Watir 驱动事物的方式(通过 OLE?)不被视为您可以远程执行的操作,因此被允许访问该页面。

然后解决方案是使用 Watir 进行 IE 自动化,或者使其证书受信任,因此您不会看到警告。

如果您想使用 Watir-Webdriver,则需要将测试服务器上使用的证书添加到受信任的根证书颁发机构存储区。注意不是默认的“个人”商店!添加证书时,您需要更改证书的放置位置,或者您基本上只为该会话授权做一次。将会有一个警告,现在来自该机构的所有证书都将被信任。我会非常小心地使用它,仅在测试系统上,并且仅用于信任来自您自己的内部测试服务器的证书。

手动进入页面后很容易做到这一点,双击红色警告提醒您证书无效。如果您做对了,您可以关闭浏览器,重新打开,进行导航,而不会出现错误。

【讨论】:

    【解决方案2】:
    driver.goto("javascript:document.getElementById('overridelink').click()")
    

    【讨论】:

    • 有趣,下次遇到这个屏幕的时候我可能得试试。在这一点上,我首选的解决方案仍然是将自签名证书添加到测试系统的受信任列表中,这会使它们的反应方式与真实用户的浏览器在我们假设的生产站点时的反应方式相同有一个有效的证书。
    猜你喜欢
    • 1970-01-01
    • 2010-10-01
    • 2016-12-13
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    相关资源
    最近更新 更多