python selenium: does not wait until page is loaded after a click() command

前端 未结 2 1967
忘掉有多难
忘掉有多难 2021-02-05 07:21

does someone know how to wait until the page is loaded? I tried all possible variants I found on the web but is simply does not work.

I need to wait after I trigger a cl

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 07:35

    Here's my version that I have used:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    def waitForLoad(inputXPath): 
        Wait = WebDriverWait(browser, PATIENCE_TIME)       
        Wait.until(EC.presence_of_element_located((By.XPATH, inputXPath)))
    

    The top line in the function is a generic wait. The second one is an expected conditions where it is trying to find an element that you know exists on the page. You can change it so instead of Xpath it does CSS_SELECTOR, NAME, ID, CLASS, etc. there are many others, but you'd have to look up the expected conditions documentation. Hope that helped, it helped me when I figured it out.

提交回复
热议问题