Selenium wait for element to be clickable python

后端 未结 2 610
后悔当初
后悔当初 2021-01-03 10:41

All, I\'m needing a little assistance with Selenium waits. I can\'t seem to figure out how to wait for an element to be ready.

The element that I am needing to wait

相关标签:
2条回答
  • 2021-01-03 10:55

    I find this to be the easiest:

    driver.implicitly_wait(10) 
    

    Where it waits for up to 10 seconds before the script might crash if expected conditions aren't met. I think it's better than always checking for the visibility of, the clickability of, or whatever it is about the element. Less effective and more error prone, however. So it would depend more on why you use selenium.

    It also lets me cut down on try/except statements in my selenium scripts, and since I've found out about this I've reduced many time.sleep() functions as well.

    0 讨论(0)
  • 2021-01-03 11:08

    Here is a link to the 'waiting' section of the Python Selenium docs: http://selenium-python.readthedocs.io/waits.html#explicit-waits

    You wait should look like this:

    element = WebDriverWait(driver, 10).until(
        EC.visibility_of((By.XPATH, ".//*[@id='line']/div[1]/a"))
    )
    
    0 讨论(0)
提交回复
热议问题