expected_conditions determine page elements
- demo2
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By import time driver = webdriver.Chrome() driver.get("http://www.baidu.com/") locator = (By.ID,"kw") try: ele = WebDriverWait(driver,10).until(EC.presence_of_element_located(locator)) driver.find_element_by_id("kw").send_keys('abc') time.sleep(1) #为了看效果 except: print("ele can't find") finally: driver.quit()
Expected conditions expected_conditions class provides a method of determining
method | Explanation |
---|---|
title_is | Determining whether the current page's title exactly equal (==) expected string and returns a Boolean value |
title_contains | Determine whether the current page title contains the expected string and returns a Boolean value |
presence_of_element_located | Determine whether an element is added to the dom tree, does not mean that certain elements visible |
visibility_of_element_located | Analyzing element is visible (visible on behalf of a non-hidden elements, and the element width and height are not equal to 0) |
visibility_of | A method as above, except the parameters for the Locator a method, the method parameter is the positioning element |
presence_of_all_elements_located | Determining whether there is at least one element is present in dom tree. Example: If there are elements of the class n pages are 'wp', as long as there is an element exists, the method returns True |
text_to_be_present_in_element | An element of judgment text contains the expected string |
text_to_be_present_in_element_value | Determine the value attribute contains an element of the expected string |
frame_to_be_available_and_switch_to_it | Determine whether the frame can switch into it, if you can, and switch into returns True, otherwise it returns False |
invisibility_of_element_located | Determine whether an element does not exist or is not visible in the dom tree |
element_to_be_clickable | Determine whether an element is visible and clickable |
staleness_of | And so an element is removed from the dom tree, note that this method also returns True or False |
element_to_be_selected | Determining whether an element is selected, generally used in the drop-down list |
element_selection_state_to_be | Determine whether an element selected in line with expectations |
element_located_selection_state_to_be | The role of the above method with the same, but the above method to the incoming positioning element, and this method pass locator |
alert_is_present | Determine whether there is a page on alert |