iOS: getAttribute("value") works for some elements, returns empty String for others


I am getting inconsistent results with the getAttribute() method when trying to retrieve the “value” attribute.


  • Appium server version: Version 1.5.3 (Ara)
  • Desktop OS/version used to run Appium if necessary: OS X 10.11.5
  • Node.js version: v6.3.0
  • Mobile platform/version under test: iOS 9.3
  • Real device or emulator/simulator: Simulator


I am working on automated tests for an app that has buttons that use a change of imagery to show when the button is selected/deselected. As such, I can not use the isSelected() method to check whether the buttons are selected. I worked with the app developer to get “selected” and “deselected” values added to the element as appropriate. When I locate the element and use .getAttribute(“value”), I get an empty String. However, I use getAttribute(“value”) elsewhere in the code and it works as expected. Examples:

This works:
return driver.findElement(NOTES_TEXT_FIELD).getAttribute(“value”).toString();
// NOTES_TEXT_FIELD element type: UIATextView
// element is located by xpath
// didn’t work until I added ".toString()

This does not work:
return driver.findElement(TABLE_CELL_A).getAttribute(“value”).toString();
// TABLE_CELL_A element type: UIAButton
// element is located by AccessibilityId; changed locator from MobileBy.AccessibilityId() to By.xpath() but it didn’t fix the problem
// tried with and without .toString(); doesn’t work either way
// if I look at the element with either the Appium inspector or the Accessibility Inspector, the “selected” and “deselected” traits added by the developer are present under “value”

Any assistance would be greatly appreciated. I searched for this issue and it seems that some others have experienced it, but the issues were either not addressed or the proposed solutions did not work for me.

Can you open the app using appium inspector and share the screen shot

If the value is set then only it will return assigned value. If value is not set then getAttribute("—") will return null. Perhaps this could be the reason in your case.

yes it will return null

Thank you for your responses. I’ve attached two screenshots: One from the Appium Inspector, and the other from the Accessibility Inspector. I apologize for not including the screenshot of the app, but this is for work and I’m not at liberty to share it.

I should also mention that return driver.findElement(TABLE_CELL_A).getAttribute("label") does return A as expected, which makes this issue even more puzzling.

Thanks in advance for your help with this.

@Jitu1888 - Please see my response above. I included screenshots. Thanks!

It looks like you’re locator is for a table cell, but you really want it to be the button which is a child element of the table cell.

@Christopher_Graham I double checked, and it’s just poor variable naming on my part. I actually am targeting the button. Definitely going to change that though. Thanks!

I would output the full page_source prior to your call to get the value attribute. That should help you troubleshoot. Possibly the value is empty at the time you’re calling it (race condition?)

@Christopher_Graham I’ll give it a shot. I’m running out of ideas. Thanks - I’ll post an update.

sorry this is off topic but i need to know how you got the hint field to show up on the inspector???

Can you try the following


I tried this, and there is no method getAttributeValue(“value”); there is only getAttribute(“value”)

Thanks for the suggestion though.

Programmatically printing the page_source right before your call for the attribute should show you exactly what Appium sees. I do this all of the time to troubleshoot issues clicking / finding / polling / etc. elements.

Then you can manually review the page_source and you’ll see if your element is even in the DOM and if it is exactly what the current state of its attributes are. Since you can see it while manually driving around in the Inspector there’s likely not an Appium issue but more likely an issue in your locator / test code / app / etc.

1 Like

Yeah, I’m actually doing that right now. Had to step away from this issue for a few days, but I’m back on it. Thanks, and I’ll keep you posted!

Thanks again for the tip, @Christopher_Graham. I debugged the test and went through the logs, and sure enough - the value for the “value” attribute was null! Here’s what I don’t get: If I start the app via the Appium UI and fire up the Inspector, I see the “Selected/Deselected” value attribute in the Accessibility Inspector. If I run the automated test and stop at a breakpoint, I don’t see the “Selected/Deselected” value attribute in the Accessibility Inspector. I am definitely using the same build in both situations. It’s also odd that getAttribute(“label”) works in both cases, but not getAttribute(“value”).

Here’s a snippet of what I pulled from the log:

And some screenshots:

From Appium Inspector (no test running):

Captured while debugging automated test:

Thanks again for your help.

I personally cannot offer any additional assistance. I’d suggest looking at some of the other iOS accessibility discussions to see if any give you some paths to explore.

Thanks for helping me troubleshoot, @Christopher_Graham. I’ll keep this thread updated and hopefully I’ll find a solution soon. Cheers!

I think this is a bug specific to the UIAButton element - possibly specific to buttons in UIATableView - because “value” can be retrieved from other elements (i.e. UIAStaticText) without issue. I also saw another thread where someone else experienced the same issue, and it doesn’t appear that a resolution was found.

Here’s a link to the issue as reported about one year ago. In this thread I made an attempt to escalate this issue, or at least confirm whether or not it is a bug: iOS App UIAButton unable to get name with get_attribute('name')

I would like to suggest researching your issue here:✓&q=is%3Aissue

If you do not see anything similar please open a new issue. You’ll get direct help from the development team, here you’re only getting help from other users.