Selenium Webdriver three ways to wait

Source: Internet
Author: User

1. Explicit wait

An explicit wait is a piece of code that you define to wait for a condition to occur before proceeding with subsequent code execution.

From selenium import Webdriver
From selenium.webdriver.common.by Import by
From Selenium.webdriver.support.ui import webdriverwait # available since 2.4.0
From Selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
Driver = Webdriver. Firefox ()
Driver.get ("http://somedomain/url_that_delays_loading")
Try
element = webdriverwait (driver, ten). Until (Ec.presence_of_element_located ((By.id, "mydynamicelement"))
Finally
Driver.quit ()

2, implicit wait, equivalent to set the global wait, when the element is positioned, set the time-out for all elements.

The implicit wait allows Webdriver to poll the DOM every other time for an element or element array, if the element or array is not immediately discovered.

The default setting is 0.

Once set, this implicit wait takes effect throughout the life cycle of the Webdriver object instance.
From selenium import Webdriver
Driver = Webdriver. Firefox ()
Driver.implicitly_wait (Ten) # seconds
Driver.get (http://www.xxx.com)
Mydynamicelement = driver.find_element_by_id ("ElementID")

3. Forced wait

Import time

Time.sleep (10)

Selenium Webdriver three ways to wait

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.