If you know the locator of that element - have a "while" loop that has a findElement()
in it, and catches NoSuchElementException
. If the element is not present, you'll catch the exception, pause for some time (though sleep
), and will start a new loop cycle. If the exception is not thrown, the element is present; change your while controlling variable to true
, and continue.
I'd suggest to have a counter how many times did the loop ran, and if it reaches a certain threshold - break out of it, with an error/exception - so you don't get stuck in an infinite loop.
Congrats - you have just implemented WebDriverWait
with the presenceOfElementLocated()
ExpectedConditions. You can go with it (the vanilla selenium version), or stick with the homegrown solution, which will give you more granular control & decision tree - but will require more coding.
If you don't have a specific element, but just want to see when the page itself changes, the algorithm is the same, but: before starting the loop, get the page source. Inside its body, get it again; if the two are different, that's your breakout condition.
This approach though is going to be affected by the slightest change in the page.