当前位置:网站首页>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 .
边栏推荐
- Sql164 next day retention rate of new users per day in November 2021
- Istio II traffic hijacking process
- Rhodamine B labeled PNA | rhodamine b-pna | biotin modified PNA | biotin modified PNA | specification information
- Synthesis route of ALA PNA alanine modified PNA peptide nucleic acid | AC ala PNA
- [training Day9] light tank [dynamic planning]
- [training Day6] triangle [mathematics] [violence]
- Inconsistent time
- Expression evaluation (stack)
- Risk control system, implemented by flink+clickhouse!
- 02 | environment preparation: how to install and configure a basic PHP development environment under windows?
猜你喜欢

2022 chemical automation control instrument test question simulation test platform operation
![[training Day6] game [mathematics]](/img/b2/09c752d789eead9a6b60f4b4b1d5d4.png)
[training Day6] game [mathematics]

Install MySQL 5.7.37 on windows10
![微服务架构 | 服务监控与隔离 - [Sentinel] TBC...](/img/28/8ca90e9dbd492688e50446f55959ff.png)
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...

Modbus communication protocol specification (Chinese) sharing
![[training Day8] series [matrix multiplication]](/img/00/06f7eb935bfd3c195e2e135197b4bd.png)
[training Day8] series [matrix multiplication]

Connect the smart WiFi remote control in the home assistant

The U.S. economy continues to be weak, and Microsoft has frozen recruitment: the cloud business and security software departments have become the hardest hit
![[training Day8] [luogu_p6335] staza [tarjan]](/img/cf/e2027549c56b8597e7cd579d737392.png)
[training Day8] [luogu_p6335] staza [tarjan]

Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
随机推荐
[mathematical modeling / mathematical programming model]
[shader realizes the flicker effect of three primary colors of television signal _shader effect Chapter 5]
Please ask a question. Follow the quick start method. After creating the table, the Flink SQL queries and displays the table structure, but there is an error when it exceeds the limit. What should we
Methods of using tyrosine modified peptide nucleic acid PNA | Tyr PNA | BZ Tyr PNA | 99Tcm survivinmrna antisense peptide nucleic acid
Vscode connected to the remote server cannot format the code / document (resolved)
Are network security and data security indistinguishable? Why is data security important?
Implementation of OA office system based on JSP
Review the code implementation of memcpy function
Conversion between VC string and timestamp
Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
English translation Chinese common dirty words
BGP - border gateway protocol
《自尊的6大支柱》自尊来源于自身的感受
Istio II traffic hijacking process
Getting started with COM programming 1- creating projects and writing interfaces
[training Day10] linear [mathematics] [thinking]
Ask a question: is there an error msg = ora-04036: instance usage when using CDC to monitor oracle
Wechat stores build order pages and automatically grab tickets
In the era of new knowledge economy, who is producing knowledge?
2022 chemical automation control instrument test question simulation test platform operation