Get value of content-desc

Try xpath
xpath = “//android.widget.EditText[contains(@content-desc,‘Enter name on card’)]”
or if you want to get the value then you can try
getAttribute(‘content-desc’)

Try below will surely work -

  1. driver.findElementByAccessibilityId(" string value");
  2. xpath = ("//android.widget.EditText[@content-desc=‘login_email_input’]");

@Telmo_Cardoso I was wondering , where did you find the list of available / supported attributes ?

Hi @igal_epshtein,

I have no idea :slight_smile:

But you made me curious. I just searched a bit and I think those are defined differently according to the driver used.

For UIA2 if you look in getElementAttributeValue() method under app/src/main/java/io/appium/uiautomator2/handler/GetElementAttribute.java you find out:

  • “name”
  • “contentDescription”
  • “text”
  • “className”
  • “resourceId”
  • “contentSize”

Then it fallback to a call to getBoolAttribute() method under app/src/main/java/io/appium/uiautomator2/model/UiObject2Element.java where you can also find:

  • “enabled”
  • “checkable”
  • “checked”
  • “clickable”
  • “focusable”
  • “focused”
  • “longClickable”
  • “scrollable”
  • “selected”
  • “displayed”
  • “password”
1 Like

Thanks !
Will try to work with them soon :slight_smile:

HI Guys,

I have below attributes:

index 0
text Remember me?
class android.widget.CheckBox
content-desc
checkable true
checked true
clickable true
enabled true
focusable true
focused false
scrollable false
long-clickable false
password false
selected false
bounds [128,1313][827,1377]
resource-id com.cmo.compliance.android:id/remember
instance 0

I am able to get boolean attribute checked etc but not able to getAttribute(“instance”). How to get instance value?

Please help me.

  1. What error you get when you try to get instance value by using getAttribute method?
  2. Why do you even need to access instance attribute: what’s the scenario? what do you want to accomplish?
  3. Screenshot?

element.getAttribute(“contentDescription”) worked. But element.getAttribute(“name”) did not give the correct value. Thanks.

You probably (I hope so) using UIAutomator2, so name doesn’t work

Thank you getAttribute("name") worked for me!

Hi, may I know whats the driver? how to setup it

.getAttribute(“content-desc”) worked for me

1 Like