python selenium expected_conditions module parses

 

 

Coding. 8 = UTF-#
from the webdriver Selenium Import
from Import By selenium.webdriver.common.by
from selenium.webdriver.support Import expected_conditions AS EC
from selenium.webdriver.support.wait Import WebDriverWait

the base_url = "http://www.baidu .com "
Driver = webdriver.Firefox ()
driver.implicitly_wait (. 5)
'' 'and a display waiting implicit waiting there, the timeout time whichever is the greater of' ''
Locator = (By.ID, 'kW ')
driver.get (base_url)

WebDriverWait (Driver, 10) .until (EC.title_is (U "Baidu, you know"))
' '' judge title, returns a Boolean value '' '

WebDriverWait (Driver, 10) .until (EC.title_contains (u "Baidu, '))
' '' Analyzing title, returns a Boolean value '' '

WebDriverWait (Driver, 10) .until (EC.presence_of_element_located((By.ID,'kw')))
'' 'Is determined whether an element is added to the dom tree, does not mean that the element must be seen, if the target return WebElement' ''

WebDriverWait (Driver, 10) .until (EC.visibility_of_element_located ((By.ID, 'SU')))
'' 'is determined whether an element is added to the inside and dom visible, and the visible representative of elements may display width and height are greater than 0' ''

WebDriverWait (Driver, 10) .until (EC.visibility_of ( driver.find_element (= By.ID by, value = 'kW')))
'' 'Analyzing element is visible, if visible returns the element' ''

WebDriverWait (Driver, 10) .until (EC.presence_of_all_elements_located ((by .CSS_SELECTOR, '. mnav')))
'' 'is determined whether there is at least one element is present in dom tree, if the target returns a list of' ''

WebDriverWait (Driver, 10) .until (EC.visibility_of_any_elements_located ((By .CSS_SELECTOR, '. mnav')))
'' 'is determined whether there is at least one element is visible on the page, if the target returns a list of' ''

WebDriverWait (Driver, 10) .until (EC.text_to_be_present_in_element ((By.XPATH, "// * [@ id = 'u1'] / a [8]"), u ' set'))
'' 'is determined whether the specified element contains the expected string, returns Boolean value'''

WebDriverWait (driver, 10) .until ( EC.text_to_be_present_in_element_value ((By.CSS_SELECTOR, '# su'), u ' Baidu,'))
'' 'determines the value of the specified attribute of the element contains the expected string, returns Boolean '' '

#WebDriverWait (Driver, 10) .until (EC.frame_to_be_available_and_switch_to_it (Locator))
' '' is determined whether the switch into the frame, if possible, switch into and return True, otherwise False '' '
# Note that no frame can be switched into a

WebDriverWait (Driver, 10) .until (EC.invisibility_of_element_located ((By.CSS_SELECTOR, '# swfEveryCookieWrap')))
'' 'is determined whether an element exists in dom or invisible, If the visible return False, invisible return the element '' '
# Note #swfEveryCookieWrap on this page is a hidden element

WebDriverWait (driver, 10) .until ( EC.element_to_be_clickable ((By.XPATH, "// * [@ = ID 'U1'] / a [. 8] "))). the click ()
'' 'is determined whether an element is visible and is enable, the representative can click on'''
driver.find_element_by_xpath("//*[@id='wrapper']/div[6]/a[1]").click()
#WebDriverWait (Driver, 10) .until (EC.element_to_be_clickable ((By.XPATH, "// * [@ ID = 'warpper'] / div [. 6] / A [. 1]"))). The Click ()

# WebDriverWait (Driver, 10) .until (EC.staleness_of (driver.find_element (By.ID, 'SU')))
'' 'waiting for an element is removed from the tree dom' ''
# suitable examples not found here

WebDriverWait (Driver, 10) .until (EC.element_to_be_selected (driver.find_element (By.XPATH, "// * [@ ID = 'NR'] / Option [. 1]")))
'' 'is determined whether an element was selected, generally used in the drop-down list '' '

WebDriverWait (Driver, 10) .until (EC.element_selection_state_to_be (driver.find_element (By.XPATH, "// * [@ ID =' NR '] / Option [. 1] "), True))
'' 'to determine whether an element selected in line with expectations'' '

WebDriverWait (Driver, 10) .until (EC.element_located_selection_state_to_be ((By.XPATH," // * [@ the above mentioned id =' nr '] / the Option [1] "), True))
'' 'to determine whether an element selected in line with expectations' ''
driver.find_element_by_xpath ( ".//*[@ ID = 'gxszButton'] / A [. 1]"). the Click ()

instance WebDriverWait = (Driver, 10) .until (EC.alert_is_present ())
'' 'is determined page the presence or absence of alert, alert if and switches to return the contents of the alert '' '


Original link: https: //blog.csdn.net/chen498858336/article/details/86383965

Guess you like

Origin www.cnblogs.com/fcc-123/p/12002734.html