Unable to select element, UI automatorviewer is attached

Unable to select element, UI automatorviewer is attached.

There are only few values displayed. How can I get appium java code to select this item on the display? I have tried everything I feel like.

Thank you.

Since you have a value for content-desc, you can find the element by “name”, which searches both text and content-desc, only if you know the expected value. Given that you have a timestamp in there, I suspect you don’t, in which case you will need to use xpath to find it.

Thank you and you are right. I will need to find by content description. One thing is only static value in the description is alarm. Also, I have never used xpath to find element by partial text. Is this feasible? Thanks again…
BTW, I have tried to findelement by name and could not get it to work with just “alarm”.

Xpath supports Regular Expressions, that should allow you to find partial text.

1 Like

You can find elements by xpath by partial text.

If you want to find your element by name, you will need to write a bit of your own code to do so. Look at Appium’s java implementation on github and you will find this method:

public RequiredElementType scrollTo(String text) {
String uiScrollables = UiScrollable(“new UiSelector().descriptionContains(”" + text + “”)") +
UiScrollable(“new UiSelector().textContains(”" + text + “”)");
return findElementByAndroidUIAutomator(uiScrollables);
}

This shows you how you can find elements that contain a particular text. This implementation, though is for scrollTo, and you want findElement. If you don’t want to write UIAutomator code, then you can look at some xpath tutorials online.

1 Like