I am trying to find a row in a table by an element, then find a element in that row and return an attribute (Or do something else).
The java selenium code here finds a table body. The getText() accurately prints out the text in the row for each row, but the s.findElement(xpath).getText() will return the unique_cell_name whether the row contains it or not. And the if statement will be entered every loop.
How do I fix it? And why does the getText() return the correct text but I can't find elements in that same rowElement?
List<WebElement> listOfRows2 = driver().findElement(By.xpath("//table/tbody")).waitUntilPresent().findElements(By.xpath("./tr"));
for(WebElement rowElement : listOfRows2){
System.out.println("getText: " + rowElement.getText());
String name = rowElement.findElement(By.xpath("//a[contains(text(),'unique_cell_name')]")).getText();
System.out.println("name : " + tooltip);
if(name.equals('unique_cell_name')){
rowElement.findElement(By.xpath("//a[contains(text(),'unique_cell_name_to_row_but_not_table')]")).doSomething();
//also want to check text in a specific column 5, where the same text might exist in the same row in the different column
rowElement.findElement(By.xpath("//td[2]")).doSomething();
break;
}
}
I am using selenium 2.53 in java with serenity/cucumber.