
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Wait Until Page is Loaded with Selenium WebDriver for Python
We can wait until the page is loaded with Selenium webdriver. There is a synchronization concept in Selenium which describes implicit and explicit wait. To wait until the page is loaded we shall use the explicit wait concept.
The explicit wait is designed such that it is dependent on the expected condition for a particular behavior of an element. For waiting until the page is loaded we shall use the expected condition presence_of_element_loaded for a particular element. Once the wait time is elapsed, the timeout error shall be thrown.
To implement explicit wait conditions, we have to take help of the WebDriverWait and ExpectedCondition class. Let us check the presence of the element below on the page and verify if the page is loaded.
Example
Code Implementation
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException from selenium.webdriver.common.by import By driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.get("https://www.tutorialspoint.com/about/about_careers.htm") // presence_of_element_located expected condition wait for 8 seconds try: w = WebDriverWait(driver, 8) w.until(expected_conditions.presence_of_element_located((By.TA G_NAME,"h1"))) print("Page load happened") exception TimeException: print("Timeout happened no page load") driver.close()