How to come out of iframe and click on Logout button using Webdriver in Java

170 views
Skip to first unread message

Umamaheshwar Thota

unread,
May 20, 2013, 2:28:58 AM5/20/13
to webd...@googlegroups.com

Hi All,


How to come out of iframe and click on Logout button using Webdriver in Java. In my application after performing some actions, my application navigates to iframe, where the webdriver hangs and no error message.

My question is: how do I come out of iframe and click on Logout button to complete the testing of that screen. The below code i have used:

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.");

After using this line also, its not working driver.switchTo().defaultContent();

Please help me on this issue. Help will be appreciated.

Please find the attached HTML Code below:

<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>

Please help me on this issue.

Michael Tamm

unread,
May 20, 2013, 5:05:20 AM5/20/13
to webd...@googlegroups.com
You can switch back to the top level window using 

driver.switchTo().defaultContent()

Kind regards, Michael


2013/5/20 Umamaheshwar Thota <thotam...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Umamaheshwar Thota

unread,
May 20, 2013, 10:24:13 AM5/20/13
to webd...@googlegroups.com
Thanks Michael for your reply.

But, the command/statement you suggested, i have used it already. After using that statement, first it worked for me then again the next day morning when i run this code, it didn't worked. Please look at the HTML code posted.

Thanks again,
Mahesh

darrell

unread,
May 21, 2013, 9:39:51 AM5/21/13
to webd...@googlegroups.com
What you are talking about and what you have posted don't match up. You are talking about iframes but there are no iframes in the HTML you have posted. Additionally, your code is getting the By locators for elements from an OR.getProperty() method. So it is not clear what the xpath for the property is. In other words, for the framework you have created you need to post the value of the properties or there is no way to put together which findElement goes with which element in the DOM.

Finally, WebDriver deals with the DOM. The DOM will look a LOT different in many cases than the HTML source code you have. So View Source is typically useless. You need to Inspect Element (Chrome), F12 (Internet Explorer) or use Firebug to examine the DOM for locators.

Darrell
Reply all
Reply to author
Forward
0 new messages