appium --- element positioning method

  We do automated testing process, the basic element is to be positioned, is automation of the soul, if not an automated test engineer, said positioning element positioning, it certainly will not do automated.

 

See how the elements

Little friends all know that if a web client can be viewed element (right click to check to see elements) through F12 How do you view the app do? app uiautomatorviewer tool by positioning elements, and then get some operation corresponds. uiautomatorviewer is Android-sdk own element positioning tool.

1. Open uiautomatorviewer tool: under android-sdk-windows \ tools

Figure 2. Click any button under to get app page Zodiac

3. positioning into the desired position by moving the mouse, and then view the lower right corner of the element properties

 

Positioning elements

1, by positioning id

# Format 
find_element_by_id ()

Click the search box to see the bottom right of element attributes

Belongs to the id attribute, perform operations such as clicking

# Get attributes ID 
driver.find_element_by_id ( ' com.taobao.taobao:id/home_searchedit ' ) .click ()

2, by positioning class_name

# Format 
find_element_by_class_name ()

Take the above chart we continue to do the analysis, found class = 'android.widget.EditText'

# 通过class_name进行定位
find_element_by_class_name('android.widget.EditText')

3、通过text定位

# 格式
find_element_by_link_text()

上图发现text属性有值为text=‘小米cc9e钢化膜’

# 通过text进行定位
find_element_by_link_text('小米cc9e钢化膜')

4、通过xpath定位

# 格式
find_element_by_xpath()

# xpath也可以通过id,class,name进行定位
# 通过id
find_element_by_xpath('//*[@resource-id='属性值']')

# 通过class
find_element_by_xpath('//*[@class='属性值']')

# 通过name
find_element_by_xpath('//*[@name='属性值']')

# 其他属性
find_element_by_xpath('//标签下[@index='属性值']')

5、通过name定位

# 格式
find_element_by_name()

# 这个工具上好像没有name属性,我们可以在web查看试试

6、通过tab_name定位

# 格式
find_element_by_tag_name()

7、通过css进行定位

# 格式
find_element_by_css_selector()

# css也可以通过其他属性定位
# 通过id
find_element_by_css_selector('#id属性')

# 通过标签定位,尽量不要用,重复的标签太多了,可以和其他属性一起使用
find_element_by_css_selector('标签名#其他属性')

# 通过class
find_element_by_css_selector('.class属性')

说明:在CSS中定位id属性前面要加"#",在class属性面前需要加“.”

详细的css定位语法见:  https://blog.csdn.net/ouyanggengcheng/article/details/77197294

 

 

 

 

定位方法不在乎多少,在乎的是如何在最需要的时候用到它(说白了就是,那个方便用那个)

 

感觉今天的知识对您有帮助的话,点个关注,持续更新中~~~~让我们在知识的海洋中翱翔

 

Guess you like

Origin www.cnblogs.com/qican/p/11189889.html