Skip to content

Instantly share code, notes, and snippets.

@sauceaaron
Last active June 11, 2019 21:03
Show Gist options
  • Save sauceaaron/b50d436ed8ab2386d72accd9354250ea to your computer and use it in GitHub Desktop.
Save sauceaaron/b50d436ed8ab2386d72accd9354250ea to your computer and use it in GitHub Desktop.
Custom wait for element text
class FindEngagement
{
public WebElement findEngagementWithText(String text) throws InterruptedException
{
List<WebElement> engagements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(EngagementListPage.engagements));
int timer = 0;
int timeout = 30;
while (timer < timeout)
{
List<WebElement> found = engagements.stream().filter(element ->
element.getText().contains(text)
).collect(Collectors.toList());
if (found.size() != 0)
{
return found.get(0);
}
engagements = driver.findElements(EngagementListPage.engagements);
timer++;
Thread.sleep(1000);
}
throw new RuntimeException("Timed out looking for element with text: " + text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment