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

36,704

Solution 1

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.

Solution 2

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

Solution 3

Appium's client comes with an Inspector tool! This will tell you the xpath of whatever element you're interested in

Solution 4

There is a way you can figure out the xpath. First get the page source from the application. This will be in xml format. Then copy the source to a xpath tester website like xpath tester. Then create the xpath and check if it works. This is assuming you already know how to create xpaths.

Share:
36,704
IWantMoore
Author by

IWantMoore

Updated on October 01, 2020

Comments

  • IWantMoore
    IWantMoore over 3 years

    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!

  • LuigiEdlCarno
    LuigiEdlCarno about 9 years
    Please add some info from linked page to your answer, because if the link stops working, your answer will be almost worthless
  • Kairat Kempirbaev
    Kairat Kempirbaev almost 9 years
    You should use UIautomatiorviewer to find the exact element or layout of your application.
  • Admin
    Admin over 8 years
    Could you please explain me how to use xpath tester?