I am currently working on automating an android application using Appium and Selenium and have run into some problems with locating elements by ID. I want to use XPATH but do not know how to get the XPATH of android UI elements. Does anyone know how to determine the XPATH of an element or know of a tool that can do this work quickly? Thanks!
Use the Spy icon button in order to get the Native/Web properties of all the objects on the screen. The easiest way to create a simple XPath query is by marking the wanted properties of an element (one or multiple properties can be used), right-clicking on them and then clicking on Copy XPath.
Go to your Android SDK installation's 'tools' folder and trigger uiautomatorviewer. bat file. From there, you can locate app elements. Visit this link which shows how to use it.
You can use android sdk tool - uiautomatorviewer( https://developer.android.com/tools/testing/testing_ui.html) it's like appium inspector, but work better for me.
com.android2.calculator3:id/digit8
For Elements with id
driver.findElement(By.id("com.example.testapp:id/txtLogin"))
For Elements with class
android.widget.EditText[@index=0]
Syntax
{ClassName}[@{anyAttributeName}={valueOfAttribute}]
Code
driver.findElements(By.className("android.widget.EditText"));//will return ARRAY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With