selenium3 + python - expected_conditions Analyzing element

expected_conditions 类

 

title_is: to determine whether the current page's title exactly equal (==) expected string and returns a Boolean value

title_contains: to determine whether the current page title contains the expected string and returns a Boolean value

presence_of_element_located: to determine whether an element is added to the dom tree It does not mean that certain elements visible

visibility_of_element_located: determining whether an element is visible visible representatives of non-hidden elements, and the width and height elements are not equal to 0.

visibility_of: doing the same thing with the above method, only the above method to pass the locator, this method is directly transmitted to the positioning element like

presence_of_all_elements_located: determining whether there is at least one element is present in dom tree. For example, if there are elements of the class n pages are 'column-md-3', as long as there is an element exists, the method returns True

text_to_be_present_in_element: determining whether or not an element contained in the desired text 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: to determine whether the frame can switch into it, if you can, and switch into returns True, otherwise it returns False

invisibility_of_element_located: determining whether an element in It does not exist or is not visible in the dom tree

element_to_be_clickable: determining whether an element is visible and enable the, so called clickable

staleness_of: an element such as removed from the dom tree, note that this method also returns True or False

element_to_be_selected: to determine whether an element is selected , and is generally used in the drop-down list

element_selection_state_to_be: determining whether an element is selected in line with expectations

element_located_selection_state_to_be: Like the above method effect, just passed the above method to locate the element, and this method pass Locator

alert_is_present: on page judgment the existence of alert



Selenium Import from the webdriver #
# Import from selenium.webdriver.support EC expected_conditions AS
#
# = Driver webdriver.Chrome ()
# driver.get ( "https://www.cnblogs.com/Teachertao/")
# # title judged complete equal to
# title = EC.title_is ( "Teacher Tao - blog Park")
# Print (title (Driver))
#
# # judge title contains
# TITLE1 = EC.title_contains ( "Teacher")
# Print (TITLE1 (Driver))
#
# # The other two writing
# r1 = EC.title_contains ( "Teacher") (Driver)
# r2 = EC.title_is ( "Teacher Tao - blog Park") (Driver)
# Print (r1, r2)

from the Selenium Import webdriver
from EC AS Import expected_conditions selenium.webdriver.support
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
mouse = driver.find_element("name","tj_briicon")
ActionChains(driver).move_to_element(mouse).perform()
# driver.find_element("link text","糯米").click()
locator = ("link text","糯米")
text = "糯米"
result = EC.text_to_be_present_in_element(locator,text)(driver)
print(result)

# 下面是失败的案例
text1 = u"糯米网"
result1 = EC.text_to_be_present_in_element(locator, text1)(driver)
print(result1)

locator2 = ("id", "su")
text2 = u"百度一下"
result2 = EC.text_to_be_present_in_element_value(locator2, text2)(driver)
print(result2)

Guess you like

Origin www.cnblogs.com/Teachertao/p/10990638.html