I was trying to figure out a way to check the checkboxes in the table grid. Usually they are defined as type='checkbox'. So I'm finding it difficult to implement using the webDriver to check the checkboxes since they are in the tags.
A sample HTML code is given below.
<tbody id="gridview-2345-body">
<tr id="gridview-2345-record-/DNA/Study1_HS.xml" class="x4-grid-row x4-grid-data-row x4-grid-row-selected" data-boundview="gridview-1270" role="row">
<td id="ext4-ext-gen1234" class="x4-grid-cell x4-grid-td" role="gridcell">
<div class="x4-grid-cell-inner " style="text-align:left;" unselectable="on">
<div class="x4-grid-row-checker"/>
</div>
</td>
<td id="ext4-ext-1235" class="x4-grid-cell x4-grid-td" role="gridcell">
<div class="x4-grid-cell-inner " style="text-align:left;" unselectable="on">
<span id="ext4-icon1568" class="fa fa-file-code-o labkey-file-icon"/>
</div>
</td>
<td id="ext4-ext-gen1236" class="x4-grid-cell x4-grid-td" role="gridcell">
<div class="x4-grid-cell-inner " style="text-align:left;" unselectable="on">
<div width="100%" height="16px">
<div style="float: left;"/>
<div style="padding-left: 8px; white-space:normal !important;">
<span style="display: inline-block; white-space: nowrap;">Study1_HS.xml</span>
</div>
</div>
</div>
</td>
</tr>
</tbody>
I tried using 'contains' in the xpath
driver.findElement(By.xpath("//*[contains(#id, 'Study1_HS.xml')]/td[1]/div/div")).click();
I'm wondering... since the TR contains the class change when the checkbox is checked, maybe clicking the TR will trigger the check. Try this and see.
String searchText = "Study1_HS.xml";
List<WebElement> rows = driver.findElements(By.tagName("tr"));
for (WebElement row : rows)
{
if (row.getText().contains(searchText))
{
row.click();
break;
}
}
So I used 'preceding' in the xpath to make it work
//span[text()='Study1_HS.xml']/preceding::td/div/div[#class='x4-grid-row-checker']
http://www.xpathtester.com/xpath/b1d50008dd4be8ab7545548c4b8238f5
Related
I'm developing an Automation test using Selenium WebDriver and Java, I need to assured that there are items in the web table, and select one of those items, but the ID is dynamic.
HTML code:
<table class="datagrid-btable" cellspacing="0" cellpadding="0" border="0" style="table-layout: auto;"> <tbody>
<tr id="datagrid-row-r4-2-0" datagrid-row-index="0" class="datagrid-row datagrid-row-selected">
<td field="PLANT_CODE" style="display:none;">
<div style="text-align: left;" class="datagrid-cell datagrid-cell-c4-PLANT_CODE">1001</div>
</td>
<td field="PLANT_NM">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-PLANT_NM">TESTE1</div>
</td>
<td field="PU_NAME" style="display:none;">
<div style=";text-align:left;" class="datagrid-cell datagrid-cell-c4-PU_NAME"></div>
</td>
<td field="SUPPLIER_CODE">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-SUPPLIER_CODE">SUP001AR</div>
</td>
<td field="SUPPLIER_NM">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-SUPPLIER_NM">SUPPLIER 001 AR</div>
</td>
<td field="ITEM_CODE">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-ITEM_CODE">ITEM001AR</div>
</td>
<td field="ITEM_NM">
<div style=";text-align:left;" class="datagrid-cell datagrid-cell-c4-ITEM_NM">ITEM1 AR</div>
</td>
<td field="WRHOUSNG_NO" style="display:none;">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-WRHOUSNG_NO"></div>
</td>
<td field="ORDE_NO" style="display:none;">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-ORDE_NO"></div>
</td>
</tr>
<tr id="datagrid-row-r4-2-1" datagrid-row-index="1" class="datagrid-row">
<td field="PLANT_CODE" style="display:none;">
<div style="text-align: left;" class="datagrid-cell datagrid-cell-c4-PLANT_CODE">1001</div>
</td>
<td field="PLANT_NM">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-PLANT_NM">BOCAR LERMA</div>
</td>
<td field="PU_NAME" style="display:none;">
<div style=";text-align:left;" class="datagrid-cell datagrid-cell-c4-PU_NAME"></div>
</td>
<td field="SUPPLIER_CODE">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-SUPPLIER_CODE">SUP001AR</div>
</td>
<td field="SUPPLIER_NM">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-SUPPLIER_NM">SUPPLIER 001 AR</div>
</td>
<td field="ITEM_CODE">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-ITEM_CODE">ITEM001AR</div>
</td>
<td field="ITEM_NM">
<div style=";text-align:left;" class="datagrid-cell datagrid-cell-c4-ITEM_NM">ITEM1 AR</div>
</td>
<td field="WRHOUSNG_NO" style="display:none;">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-WRHOUSNG_NO">PUR1</div>
</td>
<td field="ORDE_NO" style="display:none;">
<div style=";text-align:center;" class="datagrid-cell datagrid-cell-c4-ORDE_NO">PUR1</div>
</td>
</tr> </tbody> </table>
I tried "My code":
WebElement tbody = driver.findElement(By.xpath("//*[#class='datagrid-body']/tbody/tr"));
In this case, my request is returning two rows so how can I count the rows and select one of these?
Thanks
Try this step for get you want.
1. Table initialize
In your case, the table has the class datagrid-btable, the way to initialize it :
WebElement tbl = driver.findElement(By.className("datagrid-btable"));
2. Row initialize
The name tag for the web table row in general is tr, the way to initialize it :
List<WebElement> rows = tbl.findElements(By.tagName("tr"));
You can get rowCount with :
int count = rows.size();
System.out.println("count rows :" +count);
3. Column initialize
The name tag for the web table column in general are th or td, the way to initialize it :
td tag
List<WebElement> cols = rows.get(rowIndex).findElements(By.tagName("td"));
So you can select particular cell by :
String cell = cols.get(indexCol).getText();
Example for select col1 in row1 :
List<WebElement> cols = rows.get(0).findElements(By.tagName("td"));
String cell = cols.get(0).getText();
System.out.println("cell value :" +cell);
Or try this iteration for select all cell table :
for(int i=0; i<rows.size(); i++) {
//check column each in row, identification with 'td' tag
List<WebElement> cols = rows.get(i).findElements(By.tagName("td"));
//column iteration
for(int j=0; j<cols.size(); j++) {
System.out.println("row " +(i+1) +" col " +(j+1) +" : " +cols.get(j).getText());
}
}
You can get count of the rows using findElements method:
List<WebElement> rows = driver.findElements(By.cssSelector(".datagrid-btable tr.datagrid-row"));
System.out.println(rows.size());
Easy way to select row with specific text using xpath:
// get row contains text 1001
driver.findElement(By.xpath("//table[#class='datagrid-btable']//tr[#class='datagrid-row' and contains(.,'1001')]")).click();
// get row by PLANT_CODE and exact cell value
driver.findElement(By.xpath("//table[#class='datagrid-btable']//tr[#class='datagrid-row' and .//td[#field='PLANT_CODE' and div[text()='1001']]]")).click();
To find row you need, you can use stream().filter(). In the example below, rows filtered by PLANT_NM text. Using filter or rows iteration, you can write a method to filter rows by any/multi cells:
List<WebElement> rows = driver.findElements(By.cssSelector(".datagrid-btable tr.datagrid-row"));
System.out.println(rows.size());
List<WebElement> filteredRows = rows.stream().filter(element ->
element.findElement(By.cssSelector("td[field='PLANT_NM'")).getText().equals("BOCAR LERMA"))
.collect(Collectors.toList());
Assert.assertTrue(filteredRows.size() > 0, "Row with \"BOCAR LERMA\" PLANT_NM exist.");
filteredRows.get(0).click();
I've got stuck on a problem with chromedriver: list of web-elements returns only first item (also tried to complete the task with geckodriver but result is the same).
The structure of grid created by sencha is:
div-containers
table (as row)
tr (only one)
td (as column/cell)
td (as column/cell)
...
table (as row)
table (as row)
Here is HTML-code:
<div id="grid-1612-body" data-ref="body" class="x-panel-body x-grid-no-row-lines x-grid-body x-panel-body-default x-panel-body-default x-noborder-rl" role="presentation" style="width: 1069px; left: 0px; height: 585px; top: 29px;">
<div class="x-grid-view x-fit-item x-grid-view-default x-unselectable x-scroller" role="rowgroup" id="gridview-1625" tabindex="0" data-componentid="gridview-1625" style="overflow-x: hidden; overflow-y: auto; margin: 0px; width: 1069px; height: 583px;">
<div class="x-tab-guard x-tab-guard-after" tabindex="-1" data-tabindex-value="0" data-tabindex-counter="1"></div>
<div class="x-grid-item-container" role="presentation" style="width: 1052px;">
<table id="gridview-1625-record-218" role="presentation" data-boundview="gridview-1625" data-recordid="218" data-recordindex="0" class="x-grid-item" cellpadding="0" cellspacing="0" style=";width:0">
<tbody>
<tr class=" x-grid-row" role="row">
<td class="x-grid-cell x-grid-td x-grid-cell-templatecolumn-1614 x-grid-cell-first x-unselectable" style="width:40px;" role="gridcell" tabindex="-1" data-columnid="templatecolumn-1614">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">
<div> </div>
<div>
<img src="resources/pir-core/images/icons/star.gray.svg" title="Соглашение создано"> </div>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-debtAmount x-unselectable" style="width:130px;" role="gridcell" tabindex="-1" data-columnid="debtAmount">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:right;">
<b>9,36 $</b>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1616 x-unselectable" style="width:80px;" role="gridcell" tabindex="-1" data-columnid="gridcolumn-1616">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">66 month</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-debtAmountsByActionTypes x-unselectable" style="width:40px;" role="gridcell" tabindex="-1" data-columnid="debtAmountsByActionTypes">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">
<div> </div>
<div> </div>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-debtorName x-wrap-cell x-unselectable" style="width: 135px;" role="gridcell" tabindex="-1" data-columnid="debtorName" id="ext-element-43">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;" id="ext-element-42">Sherlock Holmes</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1619 x-wrap-cell x-unselectable" style="width: 135px;" role="gridcell" tabindex="-1" data-columnid="gridcolumn-1619">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">Baker Street 221B</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-ownersNumber x-unselectable" style="width:80px;" role="gridcell" tabindex="-1" data-columnid="ownersNumber" id="ext-element-39">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">1</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-lastPay x-unselectable" style="width:165px;" role="gridcell" tabindex="-1" data-columnid="lastPay">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:right;">
<table width="100%">
<tbody>
<tr>
<td style="text-align: right; font-weight: bold;">1 532,02 $</td>
<td></td>
</tr>
<tr>
<td style="text-align: right; color: silver;">117 days</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-templatecolumn-1622 x-unselectable" style="width: 67px;" role="gridcell" tabindex="-1" data-columnid="templatecolumn-1622">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">
<table width="100%">
<tbody>
<tr>
<td></td>
</tr>
<tr>
<td style="color: silver;">2596949 </td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-callStatus x-pir-cursor-pointer x-unselectable" style="width:90px;" role="gridcell" tabindex="-1" data-columnid="callStatus">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">
<div class="call-status ">
<div>
<i class="call-status-icon"></i>0
</div>
<div style="color: silver;"> </div>
</div>
</div>
</td>
<td class="x-grid-cell x-grid-td x-grid-cell-mailStatus x-pir-cursor-pointer x-grid-cell-last x-unselectable" style="width:90px;" role="gridcell" tabindex="-1" data-columnid="mailStatus">
<div unselectable="on" class="x-grid-cell-inner " style="text-align:;">
<div class="post-status ">
<div>
<i class="post-status-icon"></i>0
</div>
<div> </div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table id="gridview-1625-record-219" role="presentation" data-boundview="gridview-1625" data-recordid="219" data-recordindex="1" class="x-grid-item x-grid-item-alt" cellpadding="0" cellspacing="0" style=";width:0">
...
</table>
<table id="gridview-1625-record-220" role="presentation" data-boundview="gridview-1625" data-recordid="220" data-recordindex="2" class="x-grid-item" cellpadding="0" cellspacing="0" style=";width:0">
...
</table>
<table id="gridview-1625-record-221" role="presentation" data-boundview="gridview-1625" data-recordid="220" data-recordindex="2" class="x-grid-item" cellpadding="0" cellspacing="0" style=";width:0">
...
</table>
<table id="gridview-1625-record-222" role="presentation" data-boundview="gridview-1625" data-recordid="220" data-recordindex="2" class="x-grid-item" cellpadding="0" cellspacing="0" style=";width:0">
...
</table>
...
<div id="loadmask-1660-msgTextEl" data-ref="msgTextEl" class="x-mask-msg-text" role="presentation">Loading...</div>
</div>
</div>
</div>
</div>
And no matter how I try to get second element (or whatever not-first) there is only first element returned:
// getting n-th item of WebElements list
List<WebElement> debtorElements = driver.findElements(By.xpath("//div[#id='grid-1612-body']/div/div[#class='x-grid-item-container']/table"));
debtorElements.get(2).findElement(By.xpath("//td[#data-columnid='debtorName']/div")).getText()
// by xPath with index
driver.findElement(By.xpath("//div[#id='grid-1612-body']/div/div[#class='x-grid-item-container']/table[2]")).findElement(By.xpath("//table/tbody/tr[1]/td[5]/div")).getText()
// by xPath with id
driver.findElement(By.xpath("//table[#id='gridview-1625-record-219']")).findElement(By.xpath("//table/tbody/tr[1]/td[5]/div")).getText()
Chrome browser: Version 63.0.3239.84 (Official build), (64 bit).
Any suggestions?
When using // you are telling the WebDriver to look from the root node (<html>). Use . to tell it to look from location
debtorElements.get(2).findElement(By.xpath(".//td[#data-columnid='debtorName']/div")).getText()
^ add this
The problem might be that you are trying:
debtorElements.get(2).findElement(By.xpath("//td[#data-
columnid='debtorName']/div")).getText()
This is probably going to get text for the first element. You could do something like:
foreach(el in debtorElements)
{
el.getText();
}
This way you will try getting the text for each element within your list. I program in C#, so excuse any syntax errors.
Usually when we copy the Xpath using "Copy Xpath" in Chrome, it is not completely copied. I mean it completely gives the Xpath but not the index of element. we have to use manual indexing. try this if it works:
// by xPath with index
driver.findElement(By.xpath("//div[#id='grid-1612-body']/div/div[#class='x-grid-item-container']/table[2]")).findElement(By.xpath("//table/tbody/tr[1]/td[5]/div[your webelement index]")).getText()
//Same will be the case with Id
Also i hope you know about Iteration of elements using whatever loop you want, so go with that too
try out..
After Entering a string into a table with a checkbox next to it, I would like to click on the checkbox. In selenium, how can i iterate through the table and search for a particular text, then check the checkbox next to it.
Here's the html of the table:
<tbody>
<tr class="keyword-list-item">
<td width="75%">
<input class="keyword-selection-checkbox" type="checkbox" data-id="gw_78669090303"/>
<span>+spatspatulalas</span>
</td>
<td width="25%" style="text-align: right; padding-right: 4px;">
<span class="icon iconGoogle"/>
</td>
</tr>
<tr class="keyword-list-item">
<td width="75%">
<input class="keyword-selection-checkbox" type="checkbox" data-id="gw_102731166303"/>
<span>12.10 test post</span>
</td>
<td width="25%" style="text-align: right; padding-right: 4px;">
<span class="icon iconGoogle"/>
</td>
</tr>
You can use xpath for this. Just needs be little smart how you write the xpath. Notice the following xpath find the checkbox using the text of it.
String text = "12.10 test post";
By xpath = By.xpath("//span[contains(text(),'" + text + "')]/../input");
WebElement element = driver.findElement(xpath);
I'm having a hard time retrieving the text of an element, for some reason WebDriver can find the element but it can't retrieve the text, I'm suspecting because for some reason the element is not visible to WebDriver, I'll get to that in a moment.
Here's a snippet of the HTML:
<td id="x-auto-4169" 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">0</div>
</td>
The Xpath to get to this is
String valueXpath = "((//div[#id=\"QosDashpardPanelBottom\"]//div[#id=\"CollectorQoSPerformanceMetricsgrid\"]//div[contains(#class, \"x-grid3-row x-unselectable-single\")])[" + j + "]//div)[" + i + "]";
WebElement value = driver.findElement(By.xpath(valueXpath));
Where 'j' is the row number and 'i' is the column number respectively in a table/grid. I know that Selenium can find the element because I can do
WebElement class = driver.findElement(By.xpath(fullXpath));
String classAttr = arg.getAttribute("class");
and I return
x-grid3-cell-inner x-grid3-col-badCalls
but when I try
String cellValue = value.getText();
System.out.println(cellValue);
I get an empty string. I'm staring at my computer screen and I can see the value, it's visible, I know Selenium finds the element but I can't retrieve the text. Interestingly someone suggested to first click on the value then try to getText() so when I tried to click I got the exception:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
So I'm wondering if I'm not able to retrieve the text value because it's not visible? However if that's the case it seems strange that I can retrieve things like class attribute, tags, etc but not the text value.
Any suggestions would be greatly appreciated.
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>
After much (much) troubleshooting it turned out that I had a slight mistake on my Xpath. From my html
<div id="QosDashboardPanel0" ...
I was not accounting for multiple tabs. In my AUT I was opening a new tab, not a new browser tab but a tab in the application itself, and the whole Hmtl would remain the same except the snippet above would change to
<div id="QosDashboardPanel1" ...
I was assuming that the ID wouldn't change, well lesson learned! This is why I was running into the 'not able to click an invisible element', the element was in fact there but it was hidden behind my active tab.
Not much of a solution but I hope if someone is running into something similar this at least points them in the correct direction or makes a bell go off.
I have div structure like this
<div class="DivClass-1"> Div One
<div class="DivClass-A"> Div A </div>
</div>
<div class="DivClass-2"> Div Two
<div class="DivClass-A"> Div B </div>
</div>
<div class="DivClass-3"> Div Three
<div class="DivClass-A"> Div C </div>
</div>
<div class="DivClass-4"> Div Four
<div class="DivClass-A"> Div D </div>
</div>
and i want to parse it and convert this div structure into a table structure
can any body give an idea how to achieve this.
Use replaceall() to replace all div tags
I am not clear which <div> tag you want to convert to <tr> and <td> tag.
But, I assume DivClass-1, DivClass-2, DivClass-3, DivClass-4 are convert to <tr> tag. Others are convert to <td> tag.
I hope following code will give you little idea.
StringBuffer myHTML = new StringBuffer();
myHTML.append("<div class=\"DivClass-1\"> Div One <div class=\"DivClass-A\"> Div A </div> </div>" +
"<div class=\"DivClass-2\"> Div Two<div class=\"DivClass-A\"> Div B </div></div>" +
"<div class=\"DivClass-3\"> Div Three<div class=\"DivClass-A\"> Div C </div></div>" +
"<div class=\"DivClass-4\"> Div Four <div class=\"DivClass-A\"> Div D </div></div>");
Document myDoc = Jsoup.parse(myHTML.toString());
//get DivClass-1, DivClass-2, etc.
Elements DivClass = myDoc.select("div").not("div.DivClass-A");
Elements DivClass_A = myDoc.select("div.DivClass-A");
//rename the tag <div class="DivClass-1"> to <tr class="DivClass-1">
DivClass.tagName("tr");
//renamed the tag <div class="DivClass-A"> to <td class="DivClass-A">
DivClass_A.tagName("td");
System.out.println(myDoc.toString());
Here's the printout-
<tr class="DivClass-1">
Div One
<td class="DivClass-A"> Div A </td>
</tr>
<tr class="DivClass-2">
Div Two
<td class="DivClass-A"> Div B </td>
</tr>
<tr class="DivClass-3">
Div Three
<td class="DivClass-A"> Div C </td>
</tr>
<tr class="DivClass-4">
Div Four
<td class="DivClass-A"> Div D </td>
</tr>