我们在测试时可能都见过这个屏幕,您所需要的只是一个带有自签名证书的 HTTPS 站点,然后您会看到“此网站的安全证书有问题”屏幕,这需要您单击链接才能继续。
对于 Watir,这不是问题,我可以像处理任何其他网页一样自动化屏幕,根据其文本或 ID 值单击链接。
使用 Watir-Webdriver 就好像 HTML 中的任何内容都无法识别。我并不孤单看到这个问题
这不仅仅是尝试单击链接,几乎您在这里尝试的任何操作都会在此页面上失败,即使是一个简单的功能,例如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>
<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> </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> </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> </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> </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>