Original: https://www.cnblogs.com/lgh344902118/p/6015593.html
Webdriver three methods of waiting
1. Using webdriverwait
fromSeleniumImportWebdriver fromSelenium.webdriver.common.byImport by fromSelenium.webdriver.support.uiImportWebdriverwait#available since 2.4.0 fromSelenium.webdriver.supportImportExpected_conditions as EC#available since 2.26.0Driver =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 ()
Presence_of_element_located can be replaced by
- Title_is
- Title_contains
- presence_of_element_located
- visibility_of_element_located
- Visibility_of
- presence_of_all_elements_located
- Text_to_be_present_in_element
- Text_to_be_present_in_element_value
- Frame_to_be_available_and_switch_to_it
- invisibility_of_element_located
- Element_to_be_clickable-it is Displayed and Enabled.
- Staleness_of
- element_to_be_selected
- element_located_to_be_selected
- Element_selection_state_to_be
- Element_located_selection_state_to_be
- Alert_is_present
The ID in by.id can be replaced with ' class_name ', ' css_selector ', ' id ', ' link_text ', ' NAME ', ' partial_link_text ', ' tag_name ', ' XPATH '
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 Import = webdriver. Firefox () driver.implicitly_wait () # secondsdriver.get (http//= Driver.find _element_by_id ("elementid")
3. Forced wait
Import Timetime.sleep (10)
"Turn" selenium webdriver three kinds of waiting methods