Relative Xpath from list of WebElements - java

Is it possible to use a relative xpath after I've gathered a list of WebElements? If so what's the best way to do it?
This is what I have:
List <WebElement> rows = driver.findElements(By.xpath(rowsXpath));
int j = 1;
boolean foundCollector = false;
for(WebElement e : rows) {
String c = e.findElement(By.xpath("(//tbody)[" + j + "]//u[text()=\"" + collector + "\"])")).getText();
if(c.equals(collector)) {
foundCollector = true;
break;
}
++j;
}
the list rows contains individual rows with multiple columns and I'm trying to find the row which contains a particular name in a column. Within my for loop I was trying to use a relative xpath to look for an element, is this even possible? Or do I need to provide the whole xpath I used to find the rows with the additional xpath for the individual divs?
I'm not guaranteed the order of the columns which is why I have to do it this way.
This is the xpath I used to obtain the rows:
String rowsXpath = "//div[#id=\"QosDashpardPanelBottom\"]//div[#id=\"CollectorQoSPerformanceMetricsgrid\"]//div[contains(#class, \"x-grid3-row x-unselectable-single\")]";
Here's the HTML:
<body class=" ext-gecko ext-windows" onload="processLoaders();">
<script type="text/javascript">
<div id="topNavDiv" style="height: 90px">
<div id="bodyContentOuter" style="width: 1280px; height: 587px;">
<div id="bodyContentInner">
<script src="RLT/RLT.nocache.js" language="javascript" type="text/javascript">
<script defer="defer">
<script language="javascript" type="text/javascript">
<div id="rtcpMain" class=" x-component x-border-layout-ct" style="width: 1280px; height: 587px;">
<div id="rtcpMainWest" class=" x-panel x-component x-border-panel" style="left: 5px; top: 5px; width: 225px;">
<div id="x-auto-2" class=" x-tab-panel x-component x-border-panel" tabindex="0" hidefocus="true" style="left: 235px; top: 5px; width: 1040px;">
<div class="x-tab-panel-header x-unselectable" style="width: 1038px;" unselectable="on">
<div class="tone-rtcp-tabbed-content-panel" style="width: 1040px; height: 550px;">
<div id="x-auto-10" class=" x-component" style="overflow: auto; width: 1040px; height: 550px;">
<div id="QosDashboardPanel0" class=" x-panel x-component" style="width: 1040px;">
<div id="x-auto-13" class=" x-small-editor x-panel-header x-component x-hide-display" role="presentation">
<div id="rtcpDPBWrap" class="x-panel-bwrap" role="presentation" style="overflow: visible;">
<div class="x-panel-tbar x-panel-tbar-noheader" role="presentation" style="width: 1040px;">
<div id="rtcpDPBody" class="x-panel-body x-panel-body-noheader x-border-layout-ct" role="presentation" style="width: 1038px; height: 700px;">
<div id="QosDashboardPanelTop" class=" x-component x-border-panel x-border-layout-ct" style="left: 0px; top: 0px; width: 1038px; height: 400px;">
<div id="QosDashpardPanelBottom" class=" x-component x-border-panel x-border-layout-ct" style="left: 1px; top: 401px; width: 1036px; height: 298px;">
<div id="QosDashpardPanel_pqosChartsLC" class=" x-component x-border-panel x-border-layout-ct x-hide-display" style="left: 0px; top: 0px; width: 1036px; height: 400px;">
<div id="QosDashpardPanel_metricsTablesLC" class=" x-component x-border-panel x-border-layout-ct" style="left: 1px; top: 1px; width: 1034px; height: 296px;">
<div id="CollectorMetrics_toneletWrapper" class=" x-panel x-component x-border-panel" style="left: 1px; top: 1px; width: 330px;">
<div id="x-auto-99" class=" x-small-editor x-panel-header x-component x-hide-display" role="presentation">
<div class="x-panel-bwrap" role="presentation">
<div class="x-panel-body x-panel-body-noheader" role="presentation" style="width: 328px; height: 292px;">
<div id="CollectorMetrics" class=" x-panel x-component" style="width: 328px;">
<div id="x-auto-109" class=" x-small-editor x-panel-header x-component x-unselectable" role="presentation" unselectable="on">
<div class="x-panel-bwrap" role="presentation">
<div class="x-panel-body" role="presentation" style="width: 326px; height: 265px;">
<div id="CollectorQoSPerformanceMetricsgrid" class=" x-grid-panel x-component" style="position: relative; width: 326px; height: 265px;" tabindex="0" hidefocus="true" unselectable="">
<div class="x-grid3" role="presentation" style="width: 326px; height: 265px;">
<div class="x-grid3-viewport" role="presentation">
<div class="x-grid3-header" role="presentation">
<div class="x-grid3-scroller" role="presentation" style="width: 326px; height: 243px;">
<div class="x-grid3-body" role="presentation">
<div id="CollectorQoSPerformanceMetricsgrid_x-auto-633" class="x-grid3-row x-unselectable-single x-grid3-row-selected x-grid3-highlightrow " style="width:510px;">
<table class="x-grid3-row-table" cellspacing="0" cellpadding="0" border="0" style="width:510px;" role="presentation">
<tbody role="presentation">
<tr role="presentation">
<td id="x-auto-634" class="x-grid3-col x-grid3-cell x-grid3-td-name x-grid-cell-first " style="width:148px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-name" unselectable="on">
<u>Lync</u>
</div>
</td>
<td id="x-auto-635" class="x-grid3-col x-grid3-cell x-grid3-td-badCalls " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-badCalls" unselectable="on">36</div>
</td>
<td id="x-auto-636" class="x-grid3-col x-grid3-cell x-grid3-td-totalCalls " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-totalCalls" unselectable="on">120</div>
</td>
<td id="x-auto-637" class="x-grid3-col x-grid3-cell x-grid3-td-avgLatency " style="width:73px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLatency" unselectable="on">223</div>
</td>
<td id="x-auto-638" class="x-grid3-col x-grid3-cell x-grid3-td-avgLoss " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLoss" unselectable="on">0.80</div>
</td>
<td id="x-auto-639" class="x-grid3-col x-grid3-cell x-grid3-td-avgJitter " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgJitter" unselectable="on">29</div>
</td>
<td id="x-auto-640" class="x-grid3-col x-grid3-cell x-grid3-td-avgMOS x-grid3-cell-last " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgMOS" unselectable="on">3.86</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="CollectorQoSPerformanceMetricsgrid_x-auto-641" class="x-grid3-row x-unselectable-single " style="width:510px;">
<table class="x-grid3-row-table" cellspacing="0" cellpadding="0" border="0" style="width:510px;" role="presentation">
<tbody role="presentation">
<tr role="presentation">
<td id="x-auto-642" class="x-grid3-col x-grid3-cell x-grid3-td-name x-grid-cell-first " style="width:148px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-name" unselectable="on">
<u>CUCM-Publisher</u>
</div>
</td>
<td id="x-auto-643" class="x-grid3-col x-grid3-cell x-grid3-td-badCalls " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-badCalls" unselectable="on">3</div>
</td>
<td id="x-auto-644" class="x-grid3-col x-grid3-cell x-grid3-td-totalCalls " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-totalCalls" unselectable="on">52</div>
</td>
<td id="x-auto-645" class="x-grid3-col x-grid3-cell x-grid3-td-avgLatency " style="width:73px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLatency" unselectable="on">190</div>
</td>
<td id="x-auto-646" class="x-grid3-col x-grid3-cell x-grid3-td-avgLoss " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLoss" unselectable="on">0.79</div>
</td>
<td id="x-auto-647" class="x-grid3-col x-grid3-cell x-grid3-td-avgJitter " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgJitter" unselectable="on">31</div>
</td>
<td id="x-auto-648" class="x-grid3-col x-grid3-cell x-grid3-td-avgMOS x-grid3-cell-last " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgMOS" unselectable="on">3.98</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

Yes, this is definitely possible. See this:
// Find the outer element.
WebElement outer = driver.findElement(By.anything("whatever"));
// This doesn't work, it searches the whole page for the XPath expression.
WebElement inner = outer.findElement(By.xpath("//some/nasty/xpath"));
// This works! It takes the outer element as root.
WebElement inner = outer.findElement(By.xpath(".//some/nasty/xpath"));
Therefore, if I understood your need well, your XPath expression needs to look like this:
By.xpath("(.//tbody)[" + j + "]//div[text()=\"" + collector + "\"])")
EDIT (Holy cow, that's a lot of HTML and only a small amount of it is actually needed :).)
Now that I caught what you're after, I think you don't need this approach at all. Try this instead:
WebElement row = driver.findElement(By.xpath("id('CollectorQoSPerformanceMetricsgrid')//div[contains(#class,'x-grid3-row x-unselectable-single') and .//u[text()='" + collector + "']]"));
Only the XPath expression:
id('CollectorQoSPerformanceMetricsgrid')
//div[contains(#class,'x-grid3-row x-unselectable-single')
and .//u[text()='" + collector + "'] ]
Taken apart:
FIND ELEM WITH ID = 'CollectorQoSPerformanceMetricsgrid'
id('CollectorQoSPerformanceMetricsgrid')
FIND ALL DIV ELEMS THAT CONTAIN 'x-grid3-row x-unselectable-single' IN #CLASS
//div[contains(#class,'x-grid3-row x-unselectable-single')
AND HAVE AN <U> DESCENDANT WITH TEXT EQUAL TO collector VARIABLE
and .//u[text()='" + collector + "'] ]
This finds you only the single row you need with a single command.
If you rather want to stick with your current solution, try:
String rowsXpath = "id('CollectorQoSPerformanceMetricsgrid')//div[contains(#class, 'x-grid3-row x-unselectable-single')]";
List<WebElement> rows = driver.findElements(By.xpath(rowsXpath));
boolean foundCollector = false;
for(WebElement row : rows) {
if(!row.findElements(By.xpath(".//u[text()='" + collector + "']")).isEmpty()) {
foundCollector = true;
break;
}
}

Nowhere I found row (tr tag) in this xpath then how it will get rows count.
String rowsXpath = "//div[#id=\"QosDashpardPanelBottom\"]//div[#id=\"CollectorQoSPerformanceMetricsgrid\"]//div[contains(#class, \"x-grid3-row x-unselectable-single\")]";
You need to construct xpath something like below to get row count in particular table
int rowCount=driver.findElements(By.xpath("//table[#class='x-grid3-row-table']/tbody/tr"))
Or else if you want to find all columns in that table with particular name
construct xpath like below
int columnCount=driver.findElements(By.xpath("//table[#class='x-grid3-row-table']/tbody//tr//td[#name='RequiredName']"))

Related

FreeMarker grab variable from list when is in loop that is selected from table

I am trying to get a variable department.id for the selected department when anchor edit or delete is clicked I try with <#assgn departmentId = "${department.id}"> but that return the last id from the table.Since is in the loop I also try with onclick="<#assgn departmentId = "${department.id}">" this also return me last id is there a way to get the current id of the department when is clicked edit or delete with Apache Free Marker
HTML
<tbody>
<#assign count = 1>
<#list departmentsList as department>
<tr>
<td>${count}</td>
<td>${department.name}</td>
<td class="text-right">
<div class="dropdown dropdown-action">
<i class="material-icons">more_vert</i>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#edit_department"><i class="fa fa-pencil m-r-5"></i> Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#delete_department"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
</div>
</div>
</td>
</tr>
<#assign count ++>
</#list>
</tbody>
<tbody>
<#assign count = 1>
<#list departmentsList as department>
<tr>
<td>${count}</td>
<td>${department.name}</td>
<td class="text-right">
<div class="dropdown dropdown-action">
<i class="material-icons">more_vert</i>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#edit_department" onclick="myEditFunction(${department.id})"><i class="fa fa-pencil m-r-5"></i> Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#delete_department" onclick="myDeleteFunction(${department.id})"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
</div>
</div>
</td>
</tr>
<#assign count ++>
</#list>
</tbody>
<script>
function myDeleteFunction(departmentId) {
console.log("deleting department " + departmentId);
}
function myEditFunction(departmentId) {
console.log("editing department " + departmentId);
}
</script>

How to click on the element with text as Ok using Selenium and Java

<div id="RadWindowWrapper_alert1579252675818" class="RadWindow RadWindow_Metro rwNormalWindow rwTransparentWindow" unselectable="on" style="width: 398px; height: 148px; position: absolute; transform: none; backface-visibility: visible; touch-action: none; visibility: visible; left: 84px; top: 113px; z-index: 3012;"><table cellspacing="0" cellpadding="0" class="rwTable" style="height: 148px;"><tbody><tr class="rwTitleRow"><td class="rwCorner rwTopLeft"> </td><td class="rwTitlebar" style="cursor: move;"><div class="rwTopResize"><!-- / --></div><table align="left" cellspacing="0" cellpadding="0" class="rwTitlebarControls"><tbody><tr><td style="width: 16px;"><a class="rwIcon"></a></td><td><em unselectable="on" style="width: 318px;">Automax Message</em></td><td nowrap="" style="white-space: nowrap;"><ul class="rwControlButtons" style="width: 32px;"><li><span>Close</span></li></ul></td></tr></tbody></table></td><td class="rwCorner rwTopRight"> </td></tr><tr class="rwContentRow"><td class="rwCorner rwBodyLeft"> </td><td class="rwWindowContent" valign="top"><iframe name="alert1579252675818" src="javascript:'<html></html>';" frameborder="0" style="width: 100%; height: 100%; border: 0px; display: none;"></iframe><div id="alert1579252675818_content" style="">
<div class="rwDialogPopup radalert" style="background-image: url("../Images/InteractionImages/AutomaxSuccess.png");">
<div class="rwDialogText" id="alert1579252675818_message">
Location added successfully<br><br>
</div>
<div>
<a onclick="$find('alert1579252675818').close(true);" class="rwPopupButton" href="javascript:void(0);" tabindex="-1">
<span class="rwOuterSpan">
<span class="rwInnerSpan">Ok</span>
</span>
</a>
</div>
</div>
</div></td><td class="rwCorner rwBodyRight"> </td></tr><tr class="rwStatusbarRow" style="display: none;"><td class="rwCorner rwBodyLeft"> </td><td class="rwStatusbar"><table align="left" cellspacing="0" cellpadding="0" style="width: 100%;"><tbody><tr><td style="width: 100%;"><input id="alert1579252675818_status" readonly="" unselectable="on" tabindex="-1"><label for="alert1579252675818_status" style="display: none;">status label</label></td></tr></tbody></table></td><td class="rwCorner rwBodyRight"> </td></tr><tr class="rwFooterRow"><td class="rwCorner rwFooterLeft"> </td><td class="rwFooterCenter"> </td><td class="rwCorner rwFooterRight"> </td></tr></tbody></table></div>
Detailed HTML tag for 'Ok' button message.
name="alert1579246138835" is changing when refreshing the page.
HTML for popup / alert was present/visible on the page
The desired element is a dynamic element so to locate and click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.rwPopupButton > span.rwOuterSpan > span.rwInnerSpan"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='rwPopupButton']/span[#class='rwOuterSpan']/span[#class='rwInnerSpan' and text()='Ok']"))).click();

Making a hidden element displayable and clickable in selenium java

I have the following element:
<table class="dijit " data-dojo-attach-point="_buttonNode" cellspacing="0" cellpadding="0" role="lbox" aria-haspopup="true" tabindex="0" id="POS_domain" data-id="domain" widgetid="POS_domain" aria-expanded="false" aria- invalid="false" style="user-select: none;" popupactive="true" aria-owns="POS_domain">
<tbody role="presentation">
<tr role="presentation">
<td class="dijitReset" role="presentation">
<div class="dijitReset Text" data-dojo-attach-point="container" role="presentation">
<span role="option" aria-selected="true" class="dijitLabel ">adrija</span>
</div>
<div class="dijitContainer">
<input class="dijitInner" value="Χ " type="text" tabindex="-1" readonly="readonly" role="presentation">
</div>
<input type="hidden" data-dojo-attach-point="vn" value="adrija" hidden="true">
</td>
<td class="dijitArrowButtonContainer" data-dojo-attach-point="titleNode" role="presentation">
<input class="dijitInner" value="▼ " type="text" tabindex="-1" readonly="readonly" role="presentation">
</td>
</tr>
</tbody>
</table>
The above element is an element of dropdown and is hidden. The code that I have written is:
private WebElement domainDropdown = Driver.driver.findElement(By.id("POS_domain"));
domainDropdpwn.click();
private WebElement adrija = Driver.driver.findElement(By.xpath("//input[#value='adrija' and #data-dojo-attach-point='vn']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", adrija);
It says it's not able to find the element.
Please help. Thanks. :)
The desired <input> tag is having the attributes type="hidden" and hidden="true", so to click() on the element you can use the following solution:
//driver being an instance of WebDriver
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[#class='dijit ' and #id='POS_domain']"))).click();
WebElement my_adrija = driver.findElement(By.xpath("//input[#value='adrija' and #data-dojo-attach-point='vn']"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('hidden')", my_adrija)
((JavascriptExecutor)driver).executeScript("arguments[0].setAttribute('type','text')", my_adrija)
WebElement my_new_adrija = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#value='adrija' and #data-dojo-attach-point='vn']")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", my_new_adrija);

How to get span element into table row (Selenium Webdriver)

I'm new to Selenium webdriver. Can someone help me how to get the span element in table row
<span class="small-info" title="zim.lu#en.com , stins.gib#en.com "> zim.lu#en.com , stin.gib#en.com </span>
in below Table
<table class="k-selectable" role="grid" data-role="selectable">
<colgroup>
<tbody role="rowgroup">
<tr class="k-state-selected" role="row" data-uid="39c56242-2108-4b6d-b80f-1e2f266cd02f" aria-selected="true">
<td role="gridcell">
<div class="left-info">
<div id="item193689" class="inbox-info">
<div class="left-inboxInfo">
<h2 class="SubjecthOverflow">
<span class="small-info" title="zim.lu#en.com , stins.gib#en.com "> zim.lu#en.com , stin.gib#en.com </span>
<div id="policydiv193689">
</div>
<div class="right-inboxInfo">
</div>
</td>
</tr>
<tr class="k-alt" role="row" data-uid="32a122c7-2e7b-4a28-bb77-5fde6679e6ec">
<td role="gridcell">
<div class="left-info">
<div id="item202147" class="inbox-info">
<div class="left-inboxInfo">
<h2 class="SubjecthOverflow">
<span class="small-info" title="kev.kind#en.com , vin.kami#en.com "> ke.kin#en.com , vi.kami#en.com </span>
<div id="policydiv202147">
</div>
<div class="right-inboxInfo">
</div>
</td>
</tr>
</tbody>
</table>
I tried this code
WebElement table_element = dr.findElement(By.className("k-selectable"));
List<WebElement>tr_collection=table_element.findElements(By.xpath("//span[#class='small-info']"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
Output not showing
List<WebElement>tr_collection=dr.findElements(By.xpath("//span[#class='small-info']"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
You can find the element by using xpath or css selector
Try this below code in your list
dr.findElements(By.xpath("//*[#role='grid']/colgroup/tbody/tr/td/div/div/div/h2/span"));

how to verify the sorting in collapse group selenium web driver-java

i want to test the sorting in collapse group?? it's possible or not? Please share that how to do it. blow pic have two group 1) Branch:Clifton and 2) Branch: Holsopple.(columns are sorted by clicking on Columns heading(Contact, Type etc)).below mentioned code work where group is not exist but fail where is group on page.
when i compare the gettext in java it shows result false while sorting of the text on the page is correct,because my java code gets the text in whole column and sorting is on collapse group. I wanna write the code which verify the sorting of columns on collapse group base.
HTML is here:
<tbody>
<tr class="rgGroupHeader">
<td class="rgGroupCol">
<td colspan="9">
<p>Branch: Clifton</p>
</td>
</tr>
<td class="rgGroupCol"/>
<td style="display:none;" title="289855">289855</td>
<td style="display:none;" title="31">31</td>
<td style="display:none;"/>
<td style="display:none;" title="12">12</td>
<td style="display:none;" title="6">6</td>
<td class="col_priority">
<td title="10/24/2013">10/24/2013</td>
<td class="col_status">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl19_divStatus" class="status_active" title="Open - Active"/>
</td>
<td>
<td>
<td>
<td title="Nawaz, S (10/22/2013)">
<td class="col_manager_instruction">
<td class="col_expiry" title="N/A">N/A</td>
</tr>
<tr id="ctl00_CPHPageContents_dtgLeads_ctl00__8" class="rgRow">
<td class="rgGroupCol"/>
<td style="display:none;" title="289856">289856</td>
<td style="display:none;" title="31">31</td>
<td style="display:none;"/>
<td style="display:none;" title="11">11</td>
<td style="display:none;" title="6">6</td>
<td class="col_priority">
<td title="10/24/2013">10/24/2013</td>
<td class="col_status">
<td>
<td>
<td>
<td title="Nawaz, S (10/22/2013)">
<td class="col_manager_instruction">
<td class="col_expiry" title="11/25/2013">11/25/2013</td>
</tr>
<tr class="rgGroupHeader">
<td class="rgGroupCol">
<input id="ctl00_CPHPageContents_dtgLeads_ctl00__35__0" class="rgCollapse" type="button" title="Collapse group" onclick="$find("ctl00_CPHPageContents_dtgLeads_ctl00")._toggleGroupsExpand(this, event); return false;__doPostBack('ctl00$CPHPageContents$dtgLeads$ctl00$ctl37$ctl00','')" value=" " name="ctl00$CPHPageContents$dtgLeads$ctl00$ctl37$ctl00"/>
</td>
<td colspan="9">
<p>Branch: Holsopple</p>
</td>
</tr>
<tr id="ctl00_CPHPageContents_dtgLeads_ctl00__16" class="rgRow">
<td class="rgGroupCol"/>
<td style="display:none;" title="289768">289768</td>
<td style="display:none;" title="2">2</td>
<td style="display:none;"/>
<td style="display:none;" title="12">12</td>
<td style="display:none;" title="4">4</td>
<td class="col_priority">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_divPriority" class="priority_high" title="High"/>
</td>
<td title="06/27/2013">06/27/2013</td>
<td class="col_status">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_divStatus" class="status_active" title="Open - Active"/>
</td>
<td>
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_divInner">
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_hlnkContact" href="/Leads/Research/289768">John Ross</a>
<input id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_hdfContactID" type="hidden" value="174120" name="ctl00$CPHPageContents$dtgLeads$ctl00$ctl38$hdfContactID"/>
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_divContactCardControl" class="pos_r"/>
</div>
</td>
<td>
<div class="lead_type">
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_lnkType" class="lead_type_link" href="/Leads/Research/289768" title="Maturing CD 100">Maturing CD 100</a>
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_lnkDownArrow" class="down_arrow" onclick="showCloseTransferLayer('ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_CloseTransferLayer')" href="javascript:;"/>
<span class="pos_r">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_CloseTransferLayer">
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_lnkCloseLead" onclick="return ShowPopupForm('/Forms/Popups/CloseLead.aspx?LeadID=289768','WindowCloseLead');" href="javascript:;">Cancel Lead</a>
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_lnkTransferLead" onclick="return ShowPopupForm('/Forms/Popups/TransferLead.aspx?LeadID=289768','WindowTransferLead');" href="javascript:;">Transfer Lead</a>
</div>
</span>
</div>
</td>
<td>
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_divAssignedTo">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo" class="RadComboBox RadComboBox_Default assigned_to_combo" style="width:160px;">
<table style="border-width: 0px; border-collapse: collapse;" summary="combobox">
<tbody>
<tr class="rcbReadOnly">
<td class="rcbInputCell rcbInputCellLeft" style="width:100%;">
<input id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo_Input" class="rcbInput radPreventDecorate" type="text" readonly="readonly" value="Org, T" name="ctl00$CPHPageContents$dtgLeads$ctl00$ctl38$ddlAssignedTo" autocomplete="off"/>
</td>
<td class="rcbArrowCell rcbArrowCellRight">
<a id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a>
</td>
</tr>
</tbody>
</table>
<div class="rcbSlide" style="z-index:6000;">
<div id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default " style="display:none;">
<div class="rcbScroll rcbWidth" style="width:100%;">
<ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;">
<li class="rcbItem">Ghaffar, A</li>
<li class="rcbItem">Keller, K</li>
<li class="rcbItem">Nawaz, S</li>
<li class="rcbItem">Org, 1</li>
<li class="rcbItem">Org, T</li>
</ul>
</div>
</div>
</div>
<input id="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo_ClientState" type="hidden" name="ctl00_CPHPageContents_dtgLeads_ctl00_ctl38_ddlAssignedTo_ClientState" autocomplete="off"/>
</div>
</div>
</td>
<td/>
<td class="col_manager_instruction">
<td class="col_expiry" title="N/A">N/A</td>
</tr>
</tbody>
Java Code:
List<String> displayedNames = new ArrayList<String>();
List<String> SortedNames = new ArrayList<String>();
String getData;
Thread.sleep(thread);
for(int i=0;i<tableType.size();i++)
{
getData=tableType.get(i).getText();
System.out.println(getData);
displayedNames.add(getData);
SortedNames.add(getData);
}
System.out.println(displayedNames);
Thread.sleep(thread);
List<String> sortingOperation = displayedNames;
Thread.sleep(thread);
Collections.sort(sortingOperation);
Thread.sleep(thread);
Assert.assertEquals(SortedNames, sortingOperation);
List<String> displayedNames = new ArrayList<String>();
List<String> SortedNames = new ArrayList<String>();
Thread.sleep(10000);
WebElementtableType=action.driver.findElement(By.xpath("//[#id='table_1_core_table_content']/tbody/tr"));
Thread.sleep(10000);
List<WebElement>rowElmt=tableType.findElements(By.xpath("//tr/td[5]"));
String getData;
Thread.sleep(5000);
for(int i=2;i<rowElmt.size();i++)
{
getData=rowElmt.get(i).getText();
displayedNames.add(getData);
SortedNames.add(getData);
}
System.out.println(displayedNames);
Thread.sleep(5000);
List<String> sortingOperation = displayedNames;
Collections.sort(sortingOperation);
Assert.assertEquals(SortedNames, sortingOperation);
}

Categories

Resources