Wait for page load in Selenium (Python)

Wait for page load in Selenium (Python)

To wait until the page is loaded, the easiest way is to use a WebDriverWait to force the driver to wait until an element is visible that you know is only present on the page you are navigating to. You can do this using the expected_conditions library.

wait = WebDriverWait(self.driver, 10)
element = wait.until(expected_conditions.visibility_of_element_located((By.ID, "searchInput")))

This requires you to add the following lines to your imports:

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

Click here to see an example.

Using Java

Leave a reply

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

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.