I need to verify that a column in web table contains the exact same value for all rows.
I've done some coding but I'm looking for info about how to improve the performance:
List<WebElement> rows = driver.findElements(By.xpath(xxxx))
for(WebElement e : rows) {
if(e.getText() != expectedString) {
throwError
}
}
List<String> fetchedValues = rows
.stream()
.filter(e -> e.getText() != expectedString)
.collect(Collectors.toList());
I would like to get info if at least one of the rows does not contain expected String.
Is there any way e.g. with Java to read all values in a given column and load it to ArrayList at once?
You can try forEach method described here
Here you have an example:
@Test
public void sTest () {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.techbeamers.com/handling-html-tables-selenium-webdriver/");
List<WebElement> el = driver.findElements(By.xpath("//*[@id='post-3500']/div[1]/div/p[3]/a"));
el.forEach((e)-> {
if(!e.getText().equals(expectedString)) throwError
});
driver.quit();
}