'Selenium Automation - How to click on particular button periodically until getting another element's updated text value?
In my webpage, I have a refresh button and one Text Field,
when i landed to that page, Initially that Text Field value would be processing (In backend there is a functionality which is processing, Inorder to inform the user, textfield value is processing in UI), and after functionality is done, that Text Field would be completed
Now coming to the question, We will get to know the updated value of Text Field only when we click on the refresh button,
Is there a way to make a WebElement to be waited until that Text field has value as completed? We also need to click on that particular refresh button periodically to check that text field value became completed or not
I've found a method called textToBePresentInElement in ExpectedConditions, But using this, we cannot refresh button periodically,
Any other solution selenium webdriver is providing?
Solution 1:[1]
You need to write a custom method to wait for sometime then to perform click operation. You can see below sample code,
Code:
Create a re-usable method and write down the logic inside the method for click operation and element value check on given explicit interval times.
public static void clickUntilStatusIsChanged(By element1, By element2, String expectedStatus, int timeOutSeconds) {
WebDriverWait wait = new WebDriverWait(driver, 5);
/* The purpose of this loop is to wait for maximum of 50 seconds */
for (int i = 0; i < timeOutSeconds / 10; i++) {
if (wait.until(ExpectedConditions.textToBePresentInElementLocated(element2, expectedStatus))) {
break;
} else {
/* Waits for 10 seconds and performs click operation */
waitForTime(timeOutSeconds / 5);
driver.findElement(element1).click();
}
}
}
public static void waitForTime(int interval) {
int waitTillSeconds = interval;
long waitTillTime = Instant.now().getEpochSecond() + waitTillSeconds;
while (Instant.now().getEpochSecond() < waitTillTime) {
// Do nothing...
}
}
Pass the parameters to the re-usable method:
clickUntilStatusIsChanged(By.xpath("Element#1"), By.xpath("Element#2"), "completed", 50);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
