如何从iframe中取出并使用Java中的Webdriver单击Logout按钮

时间:2013-05-17 11:20:30

标签: webdriver selenium-webdriver

如何从iframe中出来并使用Java中的Webdriver单击Logout按钮。在我执行某些操作后的应用程序中,我的应用程序导航到iframe,其中webdriver挂起并且没有错误消息。

我的问题是:我如何走出iframe并点击Logout按钮完成该屏幕的测试。我使用的代码如下:

String msg = driver.findElement(By.xpath(OR.getProperty("CSS_Aggrement_ID"))).getText();
System.out.println(msg);
driver.findElement(By.xpath(OR.getProperty("Chk_Agree_ID"))).click();

//Taking Screen shot of the Application
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
FileUtils.copyFile(scrFile, new File("./screenshots\\Admin_Module_Users_"+cdate+"
          \\Users\\Exp Fico Addendum screen.jpg"));
Thread.sleep(2000);
System.out.println("@@@@@@@@@@@@");
driver.findElement(By.id(OR.getProperty("btn_Agree_ID"))).click();
driver.switchTo().defaultContent();
Thread.sleep(25000);
System.out.println("Accepted the CREDIT SCORING SERVICES AGREEMENT");

//Logging out the current User
driver.findElement(By.id(OR.getProperty("Logout_ID"))).click();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
System.out.println("Logged out of the current User Session.");

使用此行之后,其工作不正常的driver.switchTo()。defaultContent();

请帮我解决这个问题。将不胜感激。

请在下面找到随附的HTML代码:

<form id="aspnetForm" action="ComplianceDashboard.aspx" method="post" 
name="aspnetForm">
<div>
<script type="text/javascript">
<script type="text/javascript" src="/WebResource.axd?d=DgT4Mf0N_YMnhVqqtMJl6ITtOm-
Xk1viHB9Vm8r0uVFocGuJaKgPMl-8ToLUzthqyCSIlNvSxgcjF4L5wyRAEY6vEU1&t=634972693685435569">

<script type="text/javascript" src="/ScriptResource.axd?d= 
PmLhVym6fcJAbF6N8oKcob4OkcKdJuMeNvoZdCAHz4U4Q0qaHtiYfqHyr1IFTdWfhbYGobn9MPMr6kFnB9 
NCRJ8XUGF7hc7hr5Fa6o_syM-7UOboB6ZEADy8dFR74eifqG-tb6YdqC4X7V3nX- 
SyE9XZPya0joJB3T99qw6Fdpgiu9iy0&t=634654365694774574">

<script type="text/javascript" src="ScriptResource.axd?d=q2Vc5B1YFU9pDrTfBWIAKBUF0G6r9_ 
FGzOPwn4eK-8azwI4fzyIv_WP_rep31Ydvk9VVNFMQEhuxeubHjn0RMSnI642H4xejCZIhAwgpRiaoTPs9Lj 
zPGo9Pbz2ibVSsIKYF9oXfLnXFYCpuRJjcJueRcD0LZjsVtDpzSE0TpKi_V_LD0&t=634654365694774574">

<script type="text/javascript" src="/ScriptResource.axd?d=bgA2_TraWwLfOIi- 
qXm4QTzj4qMC_VxvPzBO8gRuZSGXbERvYOP1uk0Vw3SjH4jlyIvjudltqVRS6PhHWpBXBnDo7KbiGQGZHf9
TqtlX7itPC7J1c5rwLOn2HWBIh66aoWtws_HcZR0ZAPIYH7MeNi_Qdo81&t=634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=tKx6MMxl0ajYF54PRVK-
04BaPnmTHKNa2bxIkn-UhnTUIPGaGBWY7qxLLopFN3MIPgMDDwiCGYR-h1Krl-n9ohiSW6jt-
DT7YrgrhYezRyuK_IhEY2L1-PiUT6vG8ccRIqqMThTaV69PPyfeZRA8zXTfAh01&t=634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=Vw_LxcTJZ4e2aO6KnqG-
4O2PoAag3yGa5W1T0ofL5NX7KDlkhimlS_Wt0_XAHTgfqRg6ogQUgJDx8RNpyqmyvBa55iIpriHo6QMea2o
9eUUXCn5NBwxs9qJfg_OXmK-klT6fHACBaUFcabg52amuHdsdmd76OpDUKp1HqwxzWQzb9HYz0&t= 
634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=X6VEPsCRDKU5ndnWNCB_GA_eOTg5P-
vwzpit1O5QyN0wmto3gLjqcao02vgs5YkEgaeaZRUtiFD4IU5l7lBA0dYfQRhBa6sEz-jaTjq7RcT-
cpTew74p7eFmtfTXnpdNnST29vdZ1u3Fj8T85soLEwIi1DM1&t=634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=MFh3Z9sRP-
NTUVYMkO8oDcTGuiWtQ_4r2WJOD8AQeYoL86Rf469SXk7xtfXTXmY_QbbPKniuiWpXk_
EWpAxnh4y6jWeEQUlbEynnvGQB4cD6s-vBEYaPY0eWwW-9A7YYmyJGxWm8dCPBnSjciJEwmfagOyU1&t= 
634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=gReSUwOTlQpuI0-3h-
j3Ol2NpM3WxTx5RCjs_pE4Xfxo9_VDVzxWBqtv3dv78pWPkAU7BmfzzXVWj4JBWAIcHimclLqYXQwSY-
rZBTQWRAHxnSw3XC7BSIU6_m5m811OWyEuJr-ElKv7va1jaKhtN5KJsJNWPYg_IcKO6kDCIOIGCi_s0&t= 
634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=Byfckdz7qpMsf229tFO_ 
6L2a3cWku5BilEmXkVKnd2YlsClU_cL8BaV6IWmH11Id1PDtrf1hs1RpxMpo3v471jt62jwiHdj  
1x3MN4uSMfCMUfADxViV4N6yPT3xkI2gMdO9RGieyZlbNBRS7ya1zhVz8OHF5zUtQM2zUEPgciL0iX0gD0&t=
634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=V1mwbeDStxx0x09xeW5ITfSGm2PxL_
1TS2yXroMYZ_Un2vhIILhVWyjaVnJIwojvLUhj5DpiAgdDP1wuCWBNl7DxzsrevfVMPpZytPrMSnz45g7z
lfl4jPGIctlGUTZ6_GkASPxZdeNVtaldbeUnC3GPNIpqFVtDTHfwg3bpFhhtG0PA0&t=
634477875200920676">

<script type="text/javascript" src="/ScriptResource.axd?d=RmdufLtvsviWg7tt5_ 
mqModADNdon5lXzwoF9k7_KB22W9SGcjXi3If_0ynwBX-0_8cvWk9qGF9DLZvqhbrGpiSck1bJRMk6WMaCr4r 
inoBLvf6Fdbl31A2gF1Mlcyrm65H0HZmxRx0-nzUvmkflo-nqN8fV2brgBaHXyLataCTOCpEf0&t= 
634477875200920676">

<script type="text/javascript">
<table id="TABLE1" cellspacing="0" cellpadding="0" border="0" style="width: 100%;  
height: 100%;">

<tbody>
<tr style="height: 10%; width: 100%;">
<tr align="left" valign="top" style="height: 85%">
<td style="width: 10%; height: 80%;">
<script language="javascript" type="text/javascript">
<table cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF" width="18%"   
style="table-layout:auto; background-image: url(../Common/Images/sbtn_bg.gif); 
background-color: transparent;">

<tbody>
<tr>
<tr style="background-color:White;">
<td style="background-image:url(Common/Images/sbtn_bg.gif); background-color:White;">
<div id="ctl00_Menu1_scrollDiv" style="height:198Px; OVERFLOW: auto;">
<table id="table1" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF"   
align="center" width="90%">

<tbody>
<tr bgcolor="white">
<tr bgcolor="#FFFFFF" valign="top">
<td bgcolor="#FFFFFF" valign="top" style="width: 90%">
<table id="ctl00_Menu1_DlMenu" cellspacing="0" border="0" style="background-  
color:White;font-weight:normal;font-style:normal;text-decoration:none; width:156px; 
border-collapse:collapse;">

<tbody>
<tr>
<td>
</tr>
<tr>
</tbody>
</table>
</td>
</tr>
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
<tr bgcolor="white">
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>

<script type="text/javascript">
</td>
<td valign="top" style="width: 74%; height: 80%;">
<script src="Common/JS/popcalendar.js" type="text/javascript" language="javascript">

<div id="calendar" style="z-index:+999;position:absolute;visibility:hidden;"   
onmouseup="document.all.close.src='~/../Common/Images/Cal/close.gif'" 
onmouseover="document.all.close.src='~/../Common/Images/Cal/close.gif'"  
onclick="bShow=true">

<div id="selectMonth" style="z-index:+999;position:absolute;visibility:hidden;"   
onmouseover="document.all.spanMonth.style.borderColor='#666666';"></div>

<div id="selectYear" style="z-index:+999;position:absolute;visibility:hidden;"   
onmouseover="document.all.spanYear.style.borderColor='#666666';"></div>

<script language="javascript" type="text/javascript">
<table style="height:595px;width:100%;border-width:1px;border-color:Black;border-
style:groove;">

<tbody>
<tr>
<tr>
<tr>
<td valign="top" style="width:50%">
<td align="left" valign="top" style="width:50%">
</tr>
</tbody>
</table>

<input id="ctl00_MasterPlaceHolder_BtnDummyLoader" type="submit" style="display:none;" 
value="" name="ctl00$MasterPlaceHolder$BtnDummyLoader">
<div id="ctl00_MasterPlaceHolder_PnlLoader" style="display: none; position: fixed; 
z-index: 100001;">
<input id="ctl00_MasterPlaceHolder_BtnDummyAA" type="submit" style="display:none;" 
value="" name="ctl00$MasterPlaceHolder$BtnDummyAA">
<div id="ctl00_MasterPlaceHolder_pnlAAC" style="background-color: rgb(243, 249, 253); 
border-color: rgb(255, 153, 0); border-style: solid; height: 200px; width: 470px; 
display: none; position: fixed; z-index: 100001;">

<input id="ctl00_MasterPlaceHolder_BtnDummyRBPN" type="submit" style="display:none;" 
value="" name="ctl00$MasterPlaceHolder$BtnDummyRBPN">

<div id="ctl00_MasterPlaceHolder_pnlRbpnCon" style="background-color: rgb(243, 249,  
253); border-color: rgb(255, 153, 0); border-style: solid; height: 150px; width: 
450px; display: none; position: fixed; z-index: 100001;">

<div id="MPopLoaderBehavior_backgroundElement" class="modalBackground" style="display: 
none; position: fixed; left: 0px; top: 0px; z-index: 10000;"></div>

<div id="MPopConAABehavior_backgroundElement" class="modalBackground" style="display: 
none; position: fixed; left: 0px; top: 0px; z-index: 10000;"></div>

<div id="MPopConRBPNBehavior_backgroundElement" class="modalBackground" 
style="display: none; position: fixed; left: 0px; top: 0px; z-index: 10000;"></div>

</td>
</tr>
<tr valign="bottom" height="5%">
</tbody>
</table>

<script type="text/javascript">
</form>

0 个答案:

没有答案