How to set Selenium Python WebDriver default timeout?


We can set default timeout with Selenium webdriver. The method set_page_load_timeout is used to have a timeout for the page loading. The wait time in seconds is passed as parameter to the method.

Syntax

driver.set_page_load_timeout(5)

A TimeoutException is thrown if the page is still not loaded after the wait time is passed.

We can use the implicit wait concept in synchronization to define the default timeout time. This is a global wait time and applied to every element in the page. The method implicitly_wait is used to define implicit wait. The wait time in seconds is passed as parameter to the method.

Syntax

driver.implicitly_wait(5);

A TimeoutException is thrown if the page is still not loaded after the implicit wait time is passed.

Example

Code Implementation with set_page_load_timeout()

from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
# set_page_load_timeout to set the default page load time
driver.set_page_load_timeout(0.8)
driver.get("https://www.tutorialspoint.com/index.htm")

Code Implementation with implicit wait.

from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
#implicit wait of 0.8 seconds applied
driver.implicitly_wait(0.8)
driver.get("https://www.tutorialspoint.com/index.htm")

Updated on: 26-Oct-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements