What is the best way to check URL change with Selenium in Python?

前端 未结 5 2031
我在风中等你
我在风中等你 2020-12-10 15:42

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

5条回答
  •  甜味超标
    2020-12-10 15:52

    I was thinking to do that somehow with WebDriverWait

    Exactly. First of all, see if the built-in Expected Conditions may solve that:

    • title_is
    • title_contains

    Sample usage:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    wait = WebDriverWait(driver, 10)
    wait.until(EC.title_is("title"))
    wait.until(EC.title_contains("part of title"))
    

    If not, you can always create a custom Expected Condition to wait for url to match a desired regular expression.

提交回复
热议问题