So, what's I want to do is to run a function on a specific webpage (which is a match with my regex).
Right now I'm checking it every second and it works, but I'm sure that there is a better way (as it's flooding that website with getting requests).
while flag:
time.sleep(1)
print(driver.current_url)
if driver.current_url == "mydesiredURL_by_Regex":
time.sleep(1)
myfunction()
I was thinking to do that somehow with WebDriverWait
but not really sure how.
Here is an example using
WebdriverWait
withexpected_conditions
:Exactly. First of all, see if the built-in Expected Conditions may solve that:
title_is
title_contains
Sample usage:
If not, you can always create a custom Expected Condition to wait for url to match a desired regular expression.
To really know that the URL has changed, you need to know the old one. Using
WebDriverWait
the implementation in Java would be something like:I know the question is for Python, but it's probably easy to translate.
This is how I implemented it eventually. Works well for me: