Anna
Anna

Reputation: 157

Xpath for Android element using Appium

I am new to automation. I am working on Android + Robot Framework + Appium. I am trying to get access to this 3 locators on the picture, but nothing seems to work. screenshot from UI Automator Viewer

As you can see, some of them even don't have an id or any other elements, so I guess I should use xpath to access them, but there is so many layers...

Could anyone please help me?

Upvotes: 1

Views: 2230

Answers (3)

Anna
Anna

Reputation: 157

The main problem for me was to write a proper xpath, as I didn't know I should use classes for this.

So if I wanted to use classes and their indexes, the correct answer for third view is:

xpath=//android.view.View[@index='1']/android.widget.FrameLayout[@index='3']/android.view.View[@index='0']

And two previous paths are similar.

Upvotes: 3

saurabh-ar
saurabh-ar

Reputation: 381

You are using windows so, you can use UIAutomator available in android-sdk/tools to locate the elements. Here is an image of that tool enter image description here

Upvotes: 2

Naman
Naman

Reputation: 32036

Not sure if you are using Appium Inspector only.

But you can certainly find the X-Path to an element using it (image attached) :

Some sample image from web

Note : This is a random image from web just to depict the x-path is an attribute for elements inspected using Appium Inspector.


On the contrary to inspect elements within a WebView for an application, I would suggest using

chrome://inspect/#devices

on your chrome browser.

Upvotes: 1

Related Questions