I am using Java and Selenium to write a test. In my target application DOM, there are many tables that I need to go through. I used to use things like:
WebElement mytable = driver.findElement(By.xpath(".//table/tbody"));
List<WebElement> rows_table = mytable.findElements(By.tagName("tr"));
int rows_count = rows_table.size();
for (int row=0; row<rows_count; row++){
List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row "+row+" are "+columns_count);
for (int column=0; column<columns_count; column++){
String celtext = Columns_row.get(column).getText();
System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext);
}
System.out.println("--------------------------------------------------");
}
But I was looking for something that can handle tables in an easier way, so I searched and found:
1) selenium.getTable
2) GetTable(ElementFinder finder, JavascriptLibrary js)
but I couldn't find any good code sample for them.
Long story short I was wondering if there is any better way rather than finding .//tr or .//td to handle rows and columns in a table?