Categories
Python Answers

How to wait until element is present, visible and interactable with Python Selenium?

Spread the love

Sometimes, we want to wait until element is present, visible and interactable with Python Selenium.

In this article, we’ll look at how to wait until element is present, visible and interactable with Python Selenium.

How to wait until element is present, visible and interactable with Python Selenium?

To wait until element is present, visible and interactable with Python Selenium, we can use the wait.until method.

For instance, we write

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#...

browser.find_element_by_css_selector(".reply-button").click()

wait = WebDriverWait(browser, 10)
email = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.anonemail'))).get_attribute("value")
print(email)

to create the wait object with

wait = WebDriverWait(browser, 10)

Then we call wait.until with EC.visibility_of_element_located((By.CSS_SELECTOR, '.anonemail')) to wait for the element with the anonemail class to be visible.

We set the timeout to 10 seconds.

Conclusion

To wait until element is present, visible and interactable with Python Selenium, we can use the wait.until method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *