haimlit
haimlit

Reputation: 2582

Appium android - find element by attribute

I would like to assign a custom attribute to elements in the app's layout, and to write an automation test that locates elements by the given attribute.

for example, the layout contains:

<RelativeLayout android:id="myId"
                android:background="..."
                android:my-attribute="myValue">

And I try to locate the element by:

 androidDriver.findElement(By.xpath("//[@my-attribute=\"myValue\"]");

However the driver fails to locate the element.

I also tried

 androidDriver.findElement(By.id("myId").getAttribute("my-attribute");

But I get null on getAttribute..

Is locating by attribute supported on android? Is it supported on Appium? If so, do I have a syntax mistake?

Upvotes: 1

Views: 3930

Answers (1)

Daniel
Daniel

Reputation: 64

Sorry i cant post comments for now. Can you see my-attribute in the uiautomatorviewer? If you can then it should be possible but there are also features that is not supported depending on what android version you are using.

Upvotes: 1

Related Questions