Expand a menu inside frame with selenium java - java

I am trying to expand the option "Applications":
And this is its html:
What I have done until now:
// Wait until presence of navigation frame
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/frameset/frameset/frame[1]")));
// switch to navigation frame
driver.switchTo().frame(driver.findElement(By.name("navigation")));
// Wait until presence of Aplications option
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div/table/tbody/tr[2]/td/div[5]/a")));
// Click to expand Aplicactions options
element.click();
When it step into click I can see it is positioned over the option of Aplications because it is showing the tooltip / title "Aplications" like if we put the mouse over the option and the href of this option downside left javascript:expandCollapse('2');
I know the code is running until here because the other piece of code for login is working.
What I am not sure is the switch to frame because I have looked up for frameset and it shows that we can switch directly to the frame.
I am new, I apologize if this is messy. If something is missing to find the error, tell me to edit the post.
Thanks in advance.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="" rel="styleSheet" type="text/css">
<title></title>
</head>
<frameset name="ISCmain" rows="35,*" frameborder="1" border="1" resize="yes">
<frame title="Header mark message" src="" name="header"
noresize="" scrolling="no" marginwidth="0" marginheight="0">
<frameset cols="25%,*" resize="yes">
<frame title="Navigation mark" src="" name="navigation"
style="border-right: 1px solid #d7d7d7;" resize="yes" marginwidth="10" marginheight="10">
<html>
<head>
</head>
<body style="direction:ltr" marginwidth="10" marginheight="10" onload="initAll();" class="navtree"
leftmargin="0" topmargin="0">
<div style="direction:ltr">
<link href="" rel="styleSheet" type="text/css">
<script language="javascript">
</script>
<div class="navBody" style="background-color:#FFFFFF;">
<table height="26" width="100%" cellspacing="0" cellpadding="0"
style="background-color:#FFFFFF;">
<tbody>
<tr height="26" style="border-left: 1px solid #3970B1;background-color:#FFFFFF">
<td class="wpsGpFilter" valign="center" align="left" width="100%"
style="background-image:url(/ibm/console/images/isclite/grpfilter_background.gif);background-repeat: repeat-x;">
<select name="navFilterSelection" id="navFilterSelection" dir="ltr"
onchange="determineAction();">
<option value="allTasks" selected="" label=""></option>
<option value="com.ibm.isclite.MyTaskFilter" label=""></option>
<option value="PF+com.ibm.websphere.product" label="">
</option>
</select>
<noscript>
<input type="submit" title='' value=''>
</noscript>
</td>
</tr>
<tr>
<td align="left" colspan="2" class="navtree" style="background-color:#FFFFFF">
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigation.do?wpageid=com.ibm.isclite.welcomeportlet.layoutElement.A&moduleRef=com.ibm.isclite.ISCAdminPortlet"
target="detail" dir="ltr" title=""></a></li>
</ul>
<div nowrap="" class="main-task" style="margin-left:0.3em;"><a
style="color:#000000;text-decoration:none;"
href="javascript:expandCollapse('0');" title=""><img
src="/ibm/console/images/arrow_collapsed.gif" title="Expand"
alt="Expand" id="I0" border="0" align="absmiddle"></a></div>
<div class="nav-child-container" style="margin-left: 0.3em; display: none;"
id="N0">
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigatorCmd.do?forwardName=guidedactivity.resource&WSC=true"
target="detail" dir="ltr" title=""></a></li>
</ul>
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigatorCmd.do?forwardName=guidedactivity.web&WSC=true"
target="detail" dir="ltr" title=""></a></li>
</ul>
</div>
<div nowrap="" class="main-task" style="margin-left:0.3em;"><a
style="color:#000000;text-decoration:none;"
href="javascript:expandCollapse('1');" title=""><img
src="/ibm/console/images/arrow_collapsed.gif" title="Expand"
alt="Expand" id="I1" border="0" align="absmiddle"></a></div>
<div class="nav-child-container" style="margin-left: 0.3em; display: none;"
id="N1">
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigatorCmd.do?forwardName=ApplicationServer.content.main&WSC=true"
target="detail" dir="ltr" title=""></a></li>
</ul>
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigatorCmd.do?forwardName=WebServer.content.main&WSC=true"
target="detail" dir="ltr" title=""></a></li>
</ul>
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/com.ibm.ws.console.sib.sibresources.forwardCmd.do?forwardName=SIBMQServer.content.main&WSC=true"
target="detail" dir="ltr" title=""></a>
</li>
</ul>
</div>
<div nowrap="" class="main-task" style="margin-left:0.3em;"><a
style="color:#000000;text-decoration:none;"
href="javascript:expandCollapse('2');" title="Aplications"><img
src="/ibm/console/images/arrow_expanded.gif" title="Expand"
alt="Expand" id="I2" border="0"
align="absmiddle">Aplications</a></div>
<div class="nav-child-container" style="margin-left: 0.3em; display: block;"
id="N2">
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/navigatorCmd.do?forwardName=ApplicationDeployment.content.main&WSC=true"
target="detail" dir="ltr" title=""></a>
</li>
</ul>
<ul class="nav-child" dir="ltr">
<li class="navigation-bullet"><a style="text-decoration:none"
href="/ibm/console/com.ibm.ws.console.appmanagement.action.forwardCmd.do?forwardName=appmanagement.upload&WSC=true"
target="detail" dir="ltr" title=""></a></li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
<frame title="Content Mark"
src="/ibm/console/navigation.do?wpageid=com.ibm.isclite.welcomeportlet.layoutElement.A&moduleRef=com.ibm.isclite.ISCAdminPortlet"
name="detail" resize="yes" marginwidth="0" marginheight="0">
</frameset>
</frameset>
<noframes>
...
</noframes>
</html>

Whenever you encounter frameset remember you don't need to switch over it to let selenium interact with inside element.
Instead do switch to frame itself (Implementing WebDriverWait for more stability):
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("navigation")));
and finally your desired element you can pick :
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div/table/tbody/tr[2]/td/div[5]/a")));
// Click to expand Aplicactions options
element.click();
It not a recommendation to use Absolute xpath switch to relative xpath.

Related

button posts to current address

I'm having a problem with form. When I use button it's using post method to current address instead of one specified in form. I got no idea what's wrong in that form. I would really appreciate some help.
<form th:action:="#{/shoppingCart/addItem}" method="post">
<input hidden="hidden" th:value="*{book.id}"/><!--both name and value are taken care of by that syntax -->
<div class="row" style="margin-top: 120px">
<div class="col-xs-3">
<a th:href="#{/bookshelf}">Back to book list. </a><br/>
<img class="img-responsive shelf-book" th:src="#{adminPath}+#{/image/book/}+${book.id}+'.png'"/>
</div>
<div class="col-xs-9">
<h3 th:text="${book.title}">Book Title</h3>
<div class="row">
<div class="col-xs-5">
<h5><strong>Author: </strong><span th:text="${book.author}"></span></h5>
<p><strong>Publisher: </strong><span th:text="${book.publisher}"></span></p>
<p><strong>Publication Date: </strong><span th:text="${book.publicationDate}"></span></p>
<p><strong>Language: </strong><span th:text="${book.language}"></span></p>
<p><strong>Category: </strong><span th:text="${book.category}"></span></p>
<p><strong><span th:text="${book.format}"></span></strong> : <span th:text="${book.numberOfPages}"></span> pages</p>
<p><strong>ISBN: </strong><span th:text="${book.isbn}"></span></p>
<p><strong>Shipping weight: </strong><span th:text="${book.shippingWeight}"></span> kg</p>
</div>
<div class="col-xs-5">
<div class="panel panel-default" >
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<h4>Our price: <span>$ <span style="color: #db3208;" th:text="${book.ourPrice}"></span></span> </h4>
<p>List price: <span>$ <span style="text-decoration: line-through" th:text="${book.listPrice}"></span></span> </p>
<p>You save: <span th:text="${#numbers.formatDecimal((book.listPrice - book.ourPrice), 0, 'COMMA', 2, 'POINT')}"></span> </p>
<span>Qty: </span>
<select>
<option th:each="qty : ${qtyList}" th:value="${qty}" th:text="${qty}" ></option>
</select>
</div>
<div class="col-xs-6">
<h4 th:if="*{book.inStockNumber>9}" style="color: green">In Stock;</h4>
<h4 th:if="*{book.inStockNumber>0 and book.inStockNumber<10}" style="color: green">Only <span th:text="${book.inStockNumber}"></span> left.</h4>
<h4 th:if="*{book.inStockNumber==0}" style="color: darkred">SOLD OUT.</h4>
<button type="submit" class="btn btn-warning" style="color: black; border: solid 1px">Add to cart</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr style="color: black; height: 2px; width: 100%"/>
<p th:utext="${book.description}"></p>
</div>
</form>
Sites html code, after using the button
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="" />
<meta name="author" content="" />
<link rel="icon" href="../../favicon.ico" />
<title>Bookstore</title>
<!--Font Awesome-->
<link rel="stylesheet" href="/lib/components-font-awesome/css/font-awesome.min.css" />
<!-- Bootstrap core CSS -->
<link href="/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Custom styles for this template -->
<link href="/css/style.css" rel="stylesheet" />
</head>
<body>
<div>
<div class="page-top" style="width: 100%; height: 20px; background-color: #f46b42; margin-top: -15px"></div>
<!-- Static navbar -->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bookstore</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="/bookshelf">Books <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Browse the bookshelf</li>
<li>Opening hours & directions</li>
<li>FAQ</li>
</ul>
</li>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>SHOPPING CART</li>
<li>MY ACCOUNT</li>
<li></li>
<li></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
</div>
<div class="container">
<hr style="position: absolute; background-color: #333; z-index: -1; height: 6px; width: 100%; margin-top: 100px" />
<div class="row">
<div class="col-xs-8"><h2 class="section-headline"><span>Welcome guest.</span></h2> </div>
<div class="col-xs-4"><img src="/image/logo.png" class="img-responsive" /></div>
</div>
<img src="/image/wood.png" class="img-responsive" style="margin-top: -75px" />
<form th:action:="#{/shoppingCart/addItem}" method="post">
<input hidden="hidden" value="1" /><!--both name and value are taken care of by that syntax -->
<div class="row" style="margin-top: 120px">
<div class="col-xs-3">
Back to book list. <br />
<img class="img-responsive shelf-book" src="http://localhost:8081/adminportal/image/book/1.png" />
</div>
<div class="col-xs-9">
<h3>tre</h3>
<div class="row">
<div class="col-xs-5">
<h5><strong>Author: </strong><span>wss</span></h5>
<p><strong>Publisher: </strong><span>wew</span></p>
<p><strong>Publication Date: </strong><span>5666</span></p>
<p><strong>Language: </strong><span>polish</span></p>
<p><strong>Category: </strong><span>Biography</span></p>
<p><strong><span>Hardcover</span></strong> : <span>66</span> pages</p>
<p><strong>ISBN: </strong><span>667</span></p>
<p><strong>Shipping weight: </strong><span>7.0</span> kg</p>
</div>
<div class="col-xs-5">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<h4>Our price: <span>$ <span style="color: #db3208;">10.0</span></span> </h4>
<p>List price: <span>$ <span style="text-decoration: line-through">12.0</span></span> </p>
<p>You save: <span>2.00</span> </p>
<span>Qty: </span>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div class="col-xs-6">
<h4 style="color: green">Only <span>8</span> left.</h4>
<button type="submit" class="btn btn-warning" style="color: black; border: solid 1px">Add to cart</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr style="color: black; height: 2px; width: 100%" />
<p><p>hhgvhhu</p></p>
</div>
</form>
</div>
<div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/lib/jquery/dist/jquery.min.js"></script>
<script src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
</div>
</body>
</html>
Looks like you've got a typo:
th:action:="#{/shoppingCart/addItem}"
:=

Export paginated table in html to PDF,CSV,XLS

I am trying to export html table using js provided by Ngiriraj Table Export Demo. My table is paginated by bootstrap-table.js .
When I am exporting data in any format only 1 table page is getting exported.
Also, while exporting pdf, I am only getting only 4 columns in pdf.
The code is attached below.
Jsp page:
<div style="padding: 10px;">
<br>
<table id="table" data-search="true" data-show-columns="true"
data-pagination="true">
<thead>
<tr>
<c:forEach items="${keys}" var="keys">
<th data-field="${keys}" data-sortable="true">${keys}</th>
</c:forEach>
</tr>
</thead>
</table>
<nav class="navbar navbar-default export">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Download grid data as</a>
</div>
<ul class="nav navbar-nav">
<li><a href="#"
onClick="$('#table').tableExport({type:'excel',escape:'false'});">XLS</a></li>
<li><a href="#"
onClick="$('#table').tableExport({type:'csv',escape:'false'});">CSV</a></li>
<li><a href="#"
onClick="$('#table').tableExport({type:'pdf',escape:'false'});">PDF</a></li>
<li><a href="#"
onClick="$('#table').tableExport({type:'json',escape:'false'});">JSON</a></li>
</ul>
</div>
</nav>
</div>
I have included .js files as:
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script
src="${pageContext.request.contextPath}/static/js/tableExport.js"></script>
<script
src="${pageContext.request.contextPath}/static/js/jquery.base64.js"></script>
<script src="${pageContext.request.contextPath}/static/js/base64.js"></script>
<script src="${pageContext.request.contextPath}/static/js/sprintf.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jspdf.js"></script>
For all above .js files please refer Ngiriraj Table Export demo.
Thanks in advance.

Unable to locate webElement by LinkText using selenium webdriver?

Tried every possible way but could not locate the WebElement of WebTable.
Please find the below HTML excerpt and help me finding the WebElement "Project Costing " :
<!DOCTYPE html>
<html class="firefox win pc standard" lang="en" dir="ltr">
<head>
<body class="PSPAGE" onload="loadAllPgltData('portlets',1465250643644);">
<script type="text/javascript">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td>
<table id="ptpglts" width="100%" summary="">
<tbody>
<tr>
<td width="33%" valign="top">
<ul id="ptcol1" class="ptpgltdroppable">
<li id="ptpgltli_MENU" class="pthpli ">
<table id="MENU" class="PTPAGELET" width="100%" cellspacing="0" cellpadding="0" border="0" summary="">
<tbody>
<tr>
<tr id="ptpgltbody_row_MENU">
<td id="ptpgltbody_MENU" class="PTPAGELETBODY" width="100%">
<div id="MENU_Data" class="ptprtlcontainer">
<script id="ptPgltReloadThis" type="text/javascript">
<link type="text/css" href="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PSSTYLEREQ_1.css;wad40e4d39521f1256" rel="stylesheet">
<link type="text/css" href="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PSSTYLEDEF_TANGERINE_4.css;wa90f8b654ed2a321b" rel="stylesheet">
<script type="text/javascript">
<script src="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PT_COMMON_MIN_1.js;waaedd9d526f2073e4" type="text/javascript">
<script src="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PT_AJAX_NET_MIN_1.js;waf370f1177a8f9947" type="text/javascript">
<nav id="ptnav2pglt" aria-label="Menu">
<div id="ptnav2srch">
<div id="ptnav2pgltbody">
<ul id="ptnav2tree">
<li id="MYFAVORITES" class="ptnav2fldr" title="Create a list of frequently used transactions.">
<li id="MANAGE_QUOTE_SYSTEM" class="ptnav2fldr" title="Manage Quotes">
<li id="CO_EMPLOYEE_SELF_SERVICE" class="ptnav2fldr" title="">
<li id="CO_MANAGER_SELF_SERVICE2" class="ptnav2fldr" title="">
<li id="EPCO_CUSTOMERS" class="ptnav2fldr" title="Manage customer information.">
<li id="EPCO_CUSTOMER_CONTRACTS" class="ptnav2fldr" title="Access customer contracts.">
<li id="EPCO_ITEMS" class="ptnav2fldr" title="Manage all item-related options.">
<li id="EPPO_PURCHASING" class="ptnav2fldr" title="Manage requisitions, purchase orders, receipts, GPO contracts, and related data.">
<li id="EPCO_PROGRAM_MANAGEMENT" class="ptnav2fldr" title="Use program management tools to review program progress.">
<li id="EPCO_PROJECTS" class="ptnav2fldr" title="Access project costing.">
<div class="ptnav2toggle"> </div>
<a id="fldra_EPCO_PROJECTS" class="ptntop" href="https://pacefin.techmahindra.com/psp/PACEFIN/EMPLOYEE/ERP/s/WEBLIB_PTPP_SC.HOMEPAGE.FieldFormula.IScript_AppHP?pt_fname=EPCO_PROJECTS&FolderPath=PORTAL_ROOT_OBJECT.EPCO_PROJECTS&IsFolder=true">Project Costing</a>
For any further information regarding above Please ask.
Try below mentioned xpaths
option 1. //a[text()='Project Costing']
option 2. //*[#id='fldra_EPCO_PROJECTS'] in case this ID value is duplicate then try concatenating it with other attribute like this //*[#id='fldra_EPCO_PROJECTS'][#class='ptntop']
option 3. Or start with the table name //table[#id='ptpglts']/a
In case nothing works then try using the xpath sibling methods
option 4. Use the element just above a step above to your element //*[#class='ptnav2toggle']/following-sibling::a

Selenium WebDriver: Java: NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[#id='manage_area']/ul/li/div[2]"}

I'm having a real hard time interacting with this element. I've used FirePath, Selenium IDE, and manual construction of an XPATH to no avail. I'm trying to interact with "Group Accident". I can get Selenium to detect "Accident" by using driver.findElement(By.xpath("//div[#id='manage_area']/ul/li/div")).click();
I want to be able to open the menu and select "Add or View Plan/Options" from Group Accident.
http://i.imgur.com/gHMaXLl.jpg
Please help! Thanks.
Here's my code:
#Test
public void testAddEEBenefitsinCOLO() throws Exception {
driver.get(baseUrl + "/bcs/stored.asp");
driver.findElement(By.id("TBUserName")).clear();
driver.findElement(By.id("TBUserName")).sendKeys("test");
driver.findElement(By.name("TBPassword")).clear();
driver.findElement(By.name("TBPassword")).sendKeys("pw1");
driver.findElement(By.name("Login")).click();
Thread.sleep(2000);
driver.findElement(By.name("TBPARAM")).click();
driver.findElement(By.name("TBPARAM")).clear();
driver.findElement(By.name("TBPARAM")).sendKeys("colo1973");
driver.findElement(By.name("TBPARAM")).sendKeys(Keys.ENTER);
driver.findElement(By.id("QRY")).click();
driver.findElement(By.id("QRY")).clear();
driver.findElement(By.id("QRY")).sendKeys("Melvin");
driver.findElement(By.name("B1")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[#id='manage_area']/ul/li/div[2]")).click();
Thread.sleep(1000);
Error message:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[#id='manage_area']/ul/li/div[2]"}
Command duration or timeout: 30.01 seconds
HTML:
<div class="spAbove">
</div>
<div class="tableholder" id="ben110119014" style="width: 99%">
<form method="post" id="submitform110119014" action="EnrollChange.asp" name="ACCIDENT"
onsubmit="JavaScript: return validateChangeType(this); ">
<input type="hidden" name="TARGET" value="110119014" />
<h3>
<span onmouseover="javascript:showtip('BC110119014')">
Accident
</span>
<div id="manage_area" style="margin-left: -5px; visibility: hidden; display: inline;">
<a href="javascript:spawn_window('glossary.asp?PPVS=COLO1973#0','600','800','',0)"
title="What's this?">
<img src="images/help.gif" border="0"></a>
</div>
</h3>
<table class="textNormal sp" width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="tdata" valign="middle">
<input type="hidden" name="CHANGETYPE" id="Hidden1" value="0" />
<div id="manage_area">
<ul class="menuUL opMenu" title="Click here to view your options">
<li class="menuLI width225">
<div class="titleCell optImg" title="Click here to view your options">
<ul class="menuUL MainOptSubMenu">
<li class="menuLI"><a href="javascript: submitBenefit('16', 'submitform110119014'); "
value="16">
Add: Initial Population</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('46', 'submitform110119014'); "
value="46">
Decline Benefit: (Prompt Effective)</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('81', 'submitform110119014'); "
value="81">
Add or View Plan/Options</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('64', 'submitform110119014'); "
value="64">
Decline Benefit</a></li>
</ul>
</div>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p align="right" class="backtotop">
To Top</p>
<input type="hidden" name="TRANSID" value="5327418">
<input type="hidden" name="PPVS" value="COLO1973">
<input type="hidden" name="HST" value="SITE,BENEFITS,">
<input type="hidden" name="PF" value="BENEFITS">
<input type="hidden" name="SK" value="140062328">
<input type="hidden" name="BENCAT" value="ACCIDENT">
<input type="hidden" name="CANCHANGE" value="">
</form>
<div class="tableholder" id="ben167876400" style="width: 99%">
<form method="post" id="submitform167876400" action="EnrollChange.asp" name="GRPACC"
onsubmit="JavaScript: return validateChangeType(this); ">
<input type="hidden" name="TARGET" value="167876400" />
<h3>
<span onmouseover="javascript:showtip('BC167876400')">
Group Accident
</span>
<div id="manage_area" style="margin-left: -5px; visibility: hidden; display: inline;">
<a href="javascript:spawn_window('glossary.asp?PPVS=COLO1973#0','600','800','',0)"
title="What's this?">
<img src="images/help.gif" border="0"></a>
</div>
</h3>
<table class="textNormal sp" width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="tdata" valign="middle">
<input type="hidden" name="CHANGETYPE" id="Hidden1" value="0" />
<div id="manage_area">
<ul class="menuUL opMenu" title="Click here to view your options">
<li class="menuLI width225">
<div class="titleCell optImg" title="Click here to view your options">
<ul class="menuUL MainOptSubMenu">
<li class="menuLI"><a href="javascript: submitBenefit('16', 'submitform167876400'); "
value="16">
Add: Initial Population</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('46', 'submitform167876400'); "
value="46">
Decline Benefit: (Prompt Effective)</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('81', 'submitform167876400'); "
value="81">
Add or View Plan/Options</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('64', 'submitform167876400'); "
value="64">
Decline Benefit</a></li>
</ul>
</div>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
You can try
driver.findElement(By.linkText("Add or View Plan/Options")).click();
or
driver.findElement(By.xpath("//a[contains(.,'Add or View Plan/Options')]")).click();
As per the HTML code snippet, since "Add or View/Plan Options" is present in 2 forms above, so below is the way to click on the One under "Manage Benefit" of "Group Accident":
1- Click on the "Manage Benefits" button of "Group Accident" using this code, so that the dropdown is visible:
driver.findElement(By.xpath("//form[#id='submitform167876400']//ul[#class='menuUL opMenu']")).click();
2- Click on the "Add or View/Plan Options" submenu item under it.
driver.findElement(By.xpath("//form[#id='submitform167876400']//a[contains(text(),'Add or View Plan/Options')]")).click();

how to find search results using selenium webdriver

I am setting up a test to perform a search and after the search is complete, i want to capture the results line that says "About xxx results (x.xx seconds)". I can get this to work using the firefox webdriver, but it does not work when I use IE or Chrome driver. I need help determining what is wrong with my code. Here is the code snippet:
public void runSearch(WebDriver driver) {
WebElement element = driver.findElement(By.name("search"));
element.sendKeys("Kearney");
element.sendKeys(Keys.RETURN);
String itext = driver.findElement( By.cssSelector("div#resInfo-0")).getText();
System.out.println("Search returned '" + itext + "'.");
}
Here is the html of my page after the search has been made:
<head></head>
<body>
<header id="main_header_iphone"></header>
<div class="clear"></div>
<header id="main-header"></header>
<section>
<div class="content_nn">
<div class="subnav">
<!--
<div class="bannerBox">
<div class="btn_events"><…
-->
<div class="logo"></div>
<!--
START Search
-->
<div class="search_container">
<div id="cse" style="width:100%;">
<div class="gsc-control-cse gsc-control-cse-en">
<div class="gsc-control-wrapper-cse" dir="ltr">
<form class="gsc-search-box" accept-charset="utf-8"></form>
<div class="gsc-results-wrapper-nooverlay gsc-results-wrapper-visible">
<div class="gsc-tabsAreaInvisible"></div>
<div class="gsc-tabsAreaInvisible"></div>
<div class="gsc-above-wrapper-area">
<table class="gsc-above-wrapper-area-container" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="gsc-result-info-container">
<div id="resInfo-0" class="gsc-result-info">
About 31 results (0.11 seconds)
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="gsc-adBlockNoHeight" style="height: 0px; font-weight: normal; text-align: center;"></div>
<div class="gsc-wrapper"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript"></script>
<script type="text/javascript" src="http://www.google.com/uds/?file=search&v=1&hl=en"></script>
<link rel="stylesheet" type="text/css" href="http://www.google.com/uds/api/search/1.0/65b21018ad4df09e3eb5a21326b72d0b/default+en.css"></link>
<script type="text/javascript" src="http://www.google.com/uds/api/search/1.0/65b21018ad4df09e3eb5a21326b72d0b/default+en.I.js"></script>
<!--
END Search
-->
</div>
<div class="text_rural_h2" style="float:left; width:100%"></div>
<div class="index_page_heading" style="float:left;"></div>
<div class="letest_news2" style="float:left;"></div>
</div>
<footer id="footer"></footer>
</div>
</section>
<div id="topcontrol" style="position: fixed; bottom: 25px; right: 10px; opacity: 0; cursor: pointer;" title="Scroll Back to Top"></div>
<table class="gstl_50 gssb_c" cellspacing="0" cellpadding="0" style="width: 137px; display: none; top: 153px; position: absolute; left: 97px;"></table>
<div style="display:none"></div>
</body>
It is possible, the search result page takes more time for loading than WebDriver expects.
I propose to wait until the next page is loaded with WebDriverWait methods.
element.sendKeys("Kearney");
element.sendKeys(Keys.RETURN);
// Wait!
WebDriverWait wait = new WebDriverWait(driver, 20);
By waitFor = By.cssSelector("div#resInfo-0");
WebElement lblSearchResults = wait.until(ExpectedConditions.ElementIsVisible(waitFor));
//
String itext = lblSearchResults.getText();
Please see also this topic - WebDriver: Advanced Usage
For IE and Chrome you need an extra driver. Start with the chrome driver and check if this solves you problem.

Categories