当前位置:网站首页>Appium element positioning - App automated testing
Appium element positioning - App automated testing
2022-07-24 20:23:00 【Zeze said test】
Whatever you want app How to operate in the page , We have to find the element to operate on first . For example, if you want to click a button directly , Then you have to find this button first . If you want to enter something in the input box , Then you have to find this input box first .
The process of finding elements that need to be manipulated , It's called element positioning .
Element locator function
In most of APP During the operation , First, you must find the element that needs to be operated , This process is called element positioning .
stay Appium The function for element positioning is called find_element, He passes two parameters . The first 1 The first parameter is how to locate the element , The second parameter is the value of this method . for instance , adopt ID Locate an element , The first 1 Just fill in... With one parameter id, The first 2 The parameters represent ID Value .
el = driver.find_element('id', 'value')
Got el Is an element object , Getting the attributes of elements is very simple :
el.text # Get element text
el.rect # Get element coordinates
el.get_attribute('clickable') # Get elements clickable attribute
Element positioning tools :uiautomatorviewer
that ,id Where to get the value of ? stay SDK There is one of them. tools Catalog , This directory has a name uiautomatorviewer Tools for , Can view the attributes of each element , And of course id attribute . Directly find the corresponding file , Click to see its interface .
To view the attributes of an element , Just move the mouse over the element , The attributes of each element will be displayed on the right . Every click uiautomatorviewer This tool will be more troublesome, right , To create a shortcut , Put it on our desk , When it's needed , Just click this shortcut directly on the desktop to open .

How elements are positioned
app There are several ways to locate the main elements of automated testing :
- MobileBy.XPATH
- MobileBy.ID
- MobileBy.ACCESSIBILITY_ID
- MobileBy.ANDROID_UIAUTOMATOR
- MobileBy.CLASS_NAME
id and xpath Are the two most commonly used and grammatically common ways , Use as much as possible id To locate , If the element does not id Property or id Is not the only , Reuse xpath How elements are positioned .
Xpath Is a general path location language , It can be used in web In the web page , Can also be used in app On the page , It can make the positioning expression more accurate by combining a variety of attribute conditions , Concrete Xpath usage , You can refer to XPath How elements are positioned .
secondly Android Uiautomator This way is suitable for Java Used in language , Other languages are not very convenient to use . if necessary , You can refer to Official website Usage of .
By viewing page properties , Put the copied attributes into the function , You can locate the element . For example, you can view the of an element id by com.keda.say:id/username , The corresponding code is :
driver.find_element('id', 'com.keda.say:id/username')
You can also turn it into Xpath expression :
driver.find_element('xpath', '//*[@id="com.keda.say:id/username"]')
Get element properties
find_element Method to locate the element , You will get an element object , Use this object to get the attributes of the element , Or call the method and operation event of the property .
- element.location_in_view
- element.location
- element.rect
- element.text
- element.get_attribute(‘clickable’)
summary
In any case , do ui Automation as long as you use find_element Method , The element is obtained through element positioning , The operation can only be performed on this element later .
I'm nine , Thank you for your patience in reading , See you next time .
边栏推荐
- Maya coffee machine modeling
- Introduction to fastdfs high availability
- [FreeRTOS] 10 event flag group
- 147 set whether to cache by using the routing meta information - use of include and exclude - use of activated and deactivated
- 871. Sum of divisors
- Review the code implementation of memcpy function
- Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
- Lunch break train & problem thinking: on multidimensional array statistics of the number of elements
- Lights of thousands of families in the year of xinchou
- [training Day9] rotate [violence] [thinking]
猜你喜欢

Conversion between VC string and timestamp
![[training Day10] silly [simulation] [greed]](/img/31/94c32e05b498f8ad192f8ec2c500ca.png)
[training Day10] silly [simulation] [greed]

Implementation of OA office system based on JSP

Software testing interview tips | if you don't receive the offer, I'll wash my hair upside down

In the era of new knowledge economy, who is producing knowledge?
![[training Day9] rotate [violence] [thinking]](/img/b9/598dd0dffb9c82230f43484f9c8a1e.png)
[training Day9] rotate [violence] [thinking]
![[training Day6] dream [priority queue] [greed]](/img/1b/309b53618b8a116862971799ce4e78.jpg)
[training Day6] dream [priority queue] [greed]
![[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]](/img/75/5eca7f63758802ecf86a90a1bbdeaf.png)
[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]

From code farmer to great musician, you only need these music processing tools
![[training Day10] tree [interval DP]](/img/2d/807cabc257f67fb708ed9588769de3.png)
[training Day10] tree [interval DP]
随机推荐
Xiaomi 12s ultra products are so powerful, but foreigners can't buy Lei Jun: first concentrate on the Chinese market
870. Approximate number
Modulenotfounderror: no module named 'pysat.solvers' (resolved)
Work notes - some problems encountered when using jest
[training Day10] tree [interval DP]
Qt| control qscrollbar display position
Batch download files from the server to the local
[training Day10] silly [simulation] [greed]
MySQL stored procedure
MySQL advanced
Actual measurement of Qunhui 71000 Gigabit Network
Call Baidu AI open platform to realize image and character recognition
How to view the execution plan of a stored procedure in Youxuan database
Setting up a dual machine debugging environment for drive development (vs2017)
存储类别
[German flavor] safety: how to provide more protection for pedestrians
API data interface of A-share transaction data
Thinking of @requestbody caused by hi and hello requests
Implementation of OA office system based on JSP
VLAN Technology