0

I want to reload the page on each iteration of Awaitility.await() to check if the text of the element is changed.

My code:

Awaitility.await()
        .pollInterval(5000, TimeUnit.MILLISECONDS)
        .atMost(30, SECONDS)
        .until(() -> driver.findElement(By.id("id")).getText(), equalTo(EXPECTED_TEXT));
}

And I want to reload page on each .pollInterval, every 5 sec, with:

driver.navigate().refresh()

How can I achieve this? Or suggest a better solution with java. Thanks!

frianH
  • 7,295
  • 6
  • 20
  • 45

1 Answers1

0

Using a loop and Thread.sleep(...) would be there easiest way:

String xpath = "//*[contains(., '" + EXPECTED_TEXT +"')]";
WebElement element = null;

for (int i = 0; i < 6; i++) {
    try {
        element = driver.findElement(By.xpath(xpath));
        break;
    } catch (NoSuchElementException ex) {
        driver.navigate().refresh();
        Thread.sleep(5000);
    }
}

if (element != null) {
    // Found it!
}

Six tries multiplied by 5 seconds will give you an approximate maximum of 30 seconds.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92