Course Content
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

Selenium Implicit Wait

Selenium Implicit Wait will try to find the element on the web page. It will keep polling the web page until the element is found or until the specified time is over. If the element is not found within the provided implicit wait, we get an exception, NoSuchElementException. The implicit wait is like a global wait, which applies to every statement in the test script.

Example

Let’s understand the implicit wait with the help of an example.

# Python Selenium Script
# Python Selenium Tutorials
# www.TestingDocs.com 

from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest

class login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.base_url = "https://www.google.com"
        
    def test_example(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.implicitly_wait(60)
        driver.find_element(By.NAME,"q").send_keys("test")
        driver.find_element(By.NAME,"btnK").click()
        self.assertEqual(driver.title,"test - Google Search")
        
     
    def tearDown(self):
        self.driver.quit()
        
        
if __name__ == '__main__':
    unittest.main()          

 

Selenium Implicit Wait Python

In the above program, we have implemented the implicit wait.

driver.implicitly_wait(60)

The command will apply the wait on every find element command in the automation script. It will wait 60 seconds for the web object to appear with the given By locator mechanism. It will keep polling the web page until it finds the elements on it. If the object is found, the specified action will be performed on it. Otherwise, after 60 seconds, the test will report an exception.

Join the conversation