Reputation: 11
I am facing some issues for getting the column value from a web table in selenium webdriver. Please let me know how to get the value.
HTML
:
<table id="ext-gen1916" class="x-grid-table x-grid-table-resizer x-unselectable" cellspacing="0" cellpadding="0" border="0" style="width: 4569px; -moz-user-select: none;"><tbody>
<tr>
<tr class="x-grid-row x-grid-row-selected x-grid-row-focused x-grid-row-over">
<td class=" x-grid-cell x-grid-cell-gridcolumn-1157 x-grid-clean-cell x-grid-cell-special x-grid-cell-first">
<td id="ext-gen1949" class=" x-grid-cell x-grid-cell-actioncolumntext-1115 x-grid-clean-cell x-action-col-cell ">
<td id="ext-gen1943" class=" x-grid-cell x-grid-cell-gridcolumn-1126 x-grid-clean-cell ">
<td id="ext-gen1944" class=" x-grid-cell x-grid-cell-gridcolumn-1127 x-grid-clean-cell ">
<td id="ext-gen1917" class=" x-grid-cell x-grid-cell-gridcolumn-1128 x-grid-clean-cell ">
<div id="ext-gen1918" class="x-grid-cell-inner x-unselectable" style="; text-align: left;" unselectable="on">FP</div>
</td>
Java
code:
ele=driver.findElement(By.xpath("//td[15]/div"));
ele.getText();
System.out.println(ele.getText());
Upvotes: 1
Views: 1275
Reputation: 52665
Try to use more specific selector:
ele=driver.findElement(By.xpath("//td/div[starts-with(@id, 'ext-gen') and @class='x-grid-cell-inner x-unselectable']"));
Also check whether table
located inside an iframe
. In such case you need to switch to iframe
before "searching" for element:
driver.switchTo().frame("Frame_ID");
Upvotes: 1