Suman
Suman

Reputation: 436

How to find element using UIAutomator in appium

I am testing android hybrid application using appium. Could anyone please tell me how to find element using UIAutomator because xpath given by appium doesn't work in my case.

Many thanks!

Upvotes: 0

Views: 9740

Answers (4)

Shivam Bharadwaj
Shivam Bharadwaj

Reputation: 2294

Follow this approach to get the attributec ('contentDescription') from any element using UIautomator -

self.driver.find_element_by_accessibility_id('SomeAccessibilityID').get_attribute('contentDescription')

Upvotes: 0

Gaurav
Gaurav

Reputation: 1370

Try this:

driver.findElementsByXPath("//*[@class='android.view.View' and @index='0']");

Upvotes: 1

Alex
Alex

Reputation: 372

Do View above the Terms link and ListView have resource-id or text attributes?

I think you can try something like the following:

xpath="(//android.widget.ListView[contains(@resource-id,'some_id')]//android.widget.View)[2]/android.widget.View"

Try to find the node and then create relative path to the child.

// - means any after (any child)
/ - goes immediate after
[2] - the second item that corresponds the criteria

if you know the text attribute's value, you may use something like: [contains(@text, 'some part of text')]

Upvotes: 1

Alex
Alex

Reputation: 372

I have my app under the test on real device (but it can be on Emulator as well) connected to my desktop and run it, open some screen/page. Than I run uiautomatorviewer.bat as Administrator (strange, but I have to run it as Administrator). Than I click Device Screenshot icon on the left top corner of UI Automator Viewer and I can see the screenshot and Android classes on the right pane. I can navigate, click different elements and observe their hierarchy.

Upvotes: 2

Related Questions