Python Selenium how to wait before clicking on link

前端 未结 2 2024
小蘑菇
小蘑菇 2021-01-02 04:45

I just wonder, how to have the browser wait before clicking on a link? My goal is that I\'m scraping from a dynamic webpage, the content is dynamic but I manage to get the f

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 05:17

    You can set wait like following :

    Explicit wait :

        element = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.ID, "myElement"))
    

    Implicit wait :

     driver.implicitly_wait(20) # seconds
     driver.get("Your-URL")
     myElement = driver.find_element_by_id("myElement")
    

    You can use any of above. Both are valid.

提交回复
热议问题