Several methods targeting elements APP

Positioning and operation elements APP

webdriver positioning method provides eight elements:

positioning methods corresponding to the Python language as follows:
find_element_by_id ()
find_element_by_name ()
find_element_by_class_name ()
find_element_by_tag_name ()
find_element_by_link_text ()
find_element_by_partial_link_text ()
find_element_by_xpath ()
find_element_by_css_selector ()
Appium completely these methods inherited WebDriver defined, except that its extension, in order to fit with the positioning operation of the mobile object terminal

is positioned Detailed

1. common targeting methods:

by targeting id

(takes a value of resource-id):

Driver .find_element_by_id ( "com.wuba.zhuanzhuan: id / azo

may be directly used content behind id driver.find_element_by_id ( "azo")

 

by class_name positioning

(taking the content class)

driver.find_element_by_class_name ( "android.widget. RelativeLayout ")

 

By positioning xpath

(xpath take too content)

driver.find_element_by_xpath ( "// android.widget.LinearLayout [. 1] /android.widget.XXX")

 

by locating text

(targeting uiautomator required, the use of text content)

Driver. find_elements_by_android_uiautomator ( "new UiSelector (). text (\" + concern \ ")")

 

use here need to look through the results of text positioning is a list, not directly click. So if you want to click on the need to take an array of values, such as the following is click on the first element found

driver.find_elements_by_android_uiautomator ( "new UiSelector (). Text (\" + concern \ ")") [0] .click ()

 

by css_selector positioning (webview)

applies only to webview html pages, inherited from webdriver, the pc version of the UI test consistent

driver.find_element_by_css_selector ()

 

by link_text positioning (webview)

applies only to webview container html page, inherited from webdriver, and pc UI test version of the same

driver.

 





driver.find_element_by_name ()

 

another way 2. positioning of elements: find_element (by, value)

find_element_by_ way (value) of the actual call is find_element (by, value)

need to import this package: from selenium.webdriver.common. by import by

 

example: positioning an id ag2 the

way a: driver.find_element_by_id ( "ag2")

Second way: driver.find_element (By.ID, "ag2" )

 

this is a direct benefit of the operation by the operation value and into a tuple, then call parameter passing to the general procedure results obtained element

cateid = (By.ID, "AG2")

driver.find_element (* cateid) .click ()

 

by the operation may be:

By.ID equivalent by_id

By.CLASS_NAME equivalent by_class_name

By.XPATH corresponds by_xpath

By.NAME corresponds by_name

By.TAG_NAME corresponds by_tag_name

By.CSS_SELECTOR corresponds by_css_selector

By.LINK_TEXT corresponds by_link_text

 

3.find_elements_by_ targeting methods (value) returns the array of elements

Usage and find_element_by_ way (value) same, but returns an array. It can be accessed through a specific array index a result

 

, for example: by class_name to multiple elements, I would like to click on the first element

driver.find_elements_by_class_name ( "android.widget.RelativeLayout") [0] .click ()

 

4. another element of the array returned wording: find_elements (by, value)

usage and find_element (by, value) the same, but returns an array. It can be accessed through a specific array index a result

 

, for example: by class_name to multiple elements, I would like to click on the first element

driver.find_elements (By.CLASS_NAME, "android.widget.RelativeLayout") [0] .click ()

 

5. positioning element by element

can first find an element, then further positioning element

find_element_by_class_xpath ( "xxx"). find_element_by_name ( "yyy")


Guess you like

Origin www.cnblogs.com/zenghongfei/p/11745696.html