Recently, I have incorporated Selenium into my data collection process for a website that heavily utilizes JavaScript. While I have successfully extracted cells from the table, I am now faced with the challenge of isolating the specific "Individual" strings within each cell. For instance:
One of the cells in the table looks like this:
<tr data-ig="x:360964033.17:adr:0:tag:" tag="" adr="0" type="row">
<td idx="0" adr="0" type="cell">2014-11-02 21:15:00</td>
<td idx="1" adr="1" type="cell">AMALT</td>
<td idx="2" adr="2" type="cell">60007</td>
<td idx="3" adr="3" type="cell">107115</td>
<td class="ig9a63765d">1</td>
<td idx="9" adr="9" type="cell">576833</td>
</tr>
I am looking to individually select the row
<td idx="0" adr="0" type="cell">2014-11-02 21:15:00</td>
. How can I accomplish this?
I attempted something like List<WebElement> allRows = table.findElements(By.tagName("idx=0"));
but it didn't yield the desired results.
My current approach involves fetching the entire table and its cells as follows:
// Retrieve all TR elements from the table
List<WebElement> allRows = table.findElements(By.tagName("tr"));
// Iterate over them to obtain the cells
for (WebElement row : allRows) {
List<WebElement> cells = row.findElements(By.tagName("td"));
// Print the contents of each cell
for (WebElement cell : cells) {
System.out.println(cell.getText());
}break;
}
Thank you for any assistance provided.
Update: It appears that the layout of the table has changed dynamically:
<tr data-ig="x:360964033.17:adr:0:tag:" tag="" adr="0" type="row">
<td>2014-11-04 23:00:00</td>
<td idx="1" adr="1" type="cell">gasdjjhg</td>
<td idx="2" adr="2" type="cell">11344</td>
<td idx="3" adr="3" type="cell">14500</td>
<td idx="4" adr="4" type="cell">saddasd</td>
<td></td>
<td>sdsed</td>
<td>dsfdsf</td>
<td class="ig9a63765d">1</td>
<td></td>
</tr>
It seems the table layout keeps undergoing changes. What is your advice in handling such scenarios?