Я хочу получить данные из таблиц в пользовательском интерфейсе. Я знаю о циклическом перемещении по строкам и столбцам с использованием "tr" и "td". Но тот, который у меня есть, выглядит примерно так:
<table>
<tbody>
<tr><td>data</td><th>data</th><td>data</td><td>data</td></tr>
<tr><td>data</td><th>data</th><td>data</td><td>data</td></tr>
<tr><td>data</td><th>data</th><td>data</td><td>data</td></tr>
</tbody>
</table>
Как я могу сделать свой код общим, чтобы можно было обработать появление "TH" в середине. В настоящее время я использую этот код:
// Grab the table
WebElement table = driver.findElement(By.id(searchResultsGrid));
// Now get all the TR elements from the table
List<WebElement> allRows = table.findElements(By.tagName("tr"));
// And iterate over them, getting the cells
for (WebElement row : allRows) {
List<WebElement> cells = row.findElements(By.tagName("td"));
for (WebElement cell : cells) {
// And so on
}
}