Last active
June 11, 2019 21:03
-
-
Save sauceaaron/b50d436ed8ab2386d72accd9354250ea to your computer and use it in GitHub Desktop.
Custom wait for element text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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