'Selenium - Wait until element has a new value
Say I have an element with value = 1. Then I click on some button, it takes a while to load and then the element value updates, say value = 2. Now, what I want to do - As soon as I clicked the button, I want to constantly check the element value, wait during the time period and as soon as the value updates (i.e. 2), the wait should stop.
Currently I use, simple Thread.sleep(milliseconds) to just explicitly wait for some time.
I was hoping to use the WebDriverWait with Expected Conditions in this scenario, but not sure how to do the constant check on the value and end the wait as soon as the value gets updated to 2.
Kindly suggest how can I achieve this?
Solution 1:[1]
My solution in Java:
- By locator = By.xpath("YourXPath"); // You can use other: cssSelector, id, etc.
- WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(timeoutIntInSeconds)); // timeoutIntInSeconds is an integer value
- wait.until(ExpectedConditions.attributeToBe(locator, "value", String.valueOf(2)));
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 | Pap NĂ¡ndor |