Skip to content

Instantly share code, notes, and snippets.

@andreidbr
Created March 18, 2018 15:54
Show Gist options
  • Save andreidbr/186cbe03038f74729de8729dad9b786e to your computer and use it in GitHub Desktop.
Save andreidbr/186cbe03038f74729de8729dad9b786e to your computer and use it in GitHub Desktop.
A forEach loop in Selenium
@Test(testName = "06 Filter Functionality Test", description = "Check that the 06 Filter page functions correctly", groups = {"06Filter"})
public void verifyFilterTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[6]")).click();
driver.findElement(By.xpath("/html/body/form/input")).sendKeys("an");
Thread.sleep(500);
driver.findElement(By.xpath("/html/body/form/input")).sendKeys("dr");
if (driver.findElement(By.className("name")).isDisplayed()) {
List<WebElement> resultList = driver.findElements(By.className("name"));
for (WebElement result : resultList) {
Assert.assertTrue(result.getText().toLowerCase().contains("andr"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment