显然,我使用Selenium Webdriver进行自动化测试的网站上有一个过期的证书。我已经尝试在Internet设置中禁用证书吊销,并重新启动IE(以及Windows,只是为了安全),但无济于事。
我也尝试使用Webdriver浏览警告页面,但也没有成功。由于某种原因,它无法使用xpath或内置的“By.id”定位机制检测页面上的“继续”按钮。我对这个问题的WebDriver解决方案持开放态度,但我更喜欢允许我禁用证书撤销的解决方案。除了在VM上进行自动化测试之外,我不会使用IE,因此我并不担心安全问题。
万一WebDriver是唯一选项,这里是页面的源代码
<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 class=securityError onload="BodyLoad(); initMoreInfo('infoBlockID');">
<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=center width=* 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: none" id=CertUnknownCA name="CertUnknownCA"></DIV>
<DIV style="DISPLAY: block" id=CertExpired name="CertExpired">The security certificate presented by this website has expired or is not yet valid.</DIV>
<DIV style="DISPLAY: block" id=CertCNMismatch name="CertCNMismatch">The security certificate presented by this website was issued for a different website's address.</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=center 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=center align=left>
<H4 id=continueToSite><IMG id=ImgOverride class=actionIcon border=0 alt="Not recommended icon" src="red_shield.png"><A id=overridelink href="<href>" 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=center 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.
<LI id=errorExpl3>If you choose to ignore this error and continue, do not enter private information into the website.
<P></P>
<P id=moreInfoSeeHelpPF>For more information, see "Certificate Errors" in Internet Explorer Help.</P></LI></DIV></TD></TR></TBODY></TABLE></BODY></HTML>
这就是我尝试过的(用Java):
ieDriver.findElement(By.id("overridelink")).click();
ieDriver.findElement(By.xpath("//a[@id='overridelink']")).click();
ieDriver.findElement(By.xpath("//A[@id='overridelink']")).click();
我猜的是不行,因为引号中没有指定属性值,所以它是不正确的html。
我也试过这个:
ieDriver.findElement(By.xpath("//a[@href='<href>']")).click();
ieDriver.findElement(By.xpath("//A[@id='<href>']")).click();
其中
<href>
表示实际的网址。
我也无法使用相同的方法找到周围的标签。
注意:这对我也不起作用:Webdriver not finding elements in remote IE
我怀疑,因为它不会减轻安全问题,因为它信任过期的证书。
答案 0 :(得分:0)
如果这是IE正在创建的警告框,您可以尝试.SwitchTo()
我将其用于警告框。
WebDriver.SwitchTo().Alert().Accept();
希望有所帮助
答案 1 :(得分:0)
嗯,一个有效的解决方案就是创建一个具有可接受结束日期的新证书。仅当您有权访问服务器,管理员允许这样做,并且不介意签署自己的证书(至少是暂时的)时,这种方法才有效。我真的不喜欢这个解决方案,但因为它似乎是我问题的有效答案,所以我会选择它。我将专门创建一个与WebDriver功能相关的新问题。