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