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

前端 未结 5 2026
我在风中等你
我在风中等你 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:47

    Use url_matches Link to match a regex pattern with a url. It does re.search(pattern, url)

    from selenium import webdriver
    import re
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    
    pattern='https://www.example.com/'
    driver = webdriver.Chrome()
    wait = WebDriverWait(driver,10)
    
    wait.until(EC.url_matches(pattern))
    

提交回复
热议问题