Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the XPATH of Android UI elements. Selenium + Appium

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!

like image 320
IWantMoore Avatar asked Jun 11 '14 15:06

IWantMoore


People also ask

How do I find the XPath of an element in Appium?

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.

Where is XPath in android emulator?

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.


2 Answers

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.

like image 98
user220448 Avatar answered Nov 15 '22 02:11

user220448


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
like image 44
Kairat Kempirbaev Avatar answered Nov 15 '22 03:11

Kairat Kempirbaev