Python Selenium Webdriver.implicitly_wait(seconds)

This method configures the Python Selenium web driver to wait up to N seconds before it gives up searching for an element on a page.

By default, implicitly_wait is set to 0, which means that if an element is not immediately available, it will fail immediately if, upon loading the page, it doesn’t find the expected HTML element.

It is advisable to set implicitly wait to a reasonable delay in order to give enough time to place all the elements in the page.

Since most websites nowadays use client-side rendering, this parameter is of crucial importance, so you should not forget to set it.

Example

Setting implicitly_wait to wait up to 30 seconds for element to appear.

url = "https://somewebsite.com/"

wd.get(url)
# Setting implicitly_wait to 30 seconds
wd.implicitly_wait(30)

# searching for an input field
search_field = wd.find_element_by_id("id_ac_descrizione")
search_field.send_keys("Nativita")
searchButton = wd.find_element_by_id("sc_b_pesq_bot")
searchButton.click()
table = wd.find_element_by_class_name("scGridTabela")]

Resources

https://selenium-python.readthedocs.io/waits.html

Recommended Courses for Data Science


Posted

in

,

by