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

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

findElement(TABLE_CELL_.A).getAttributeValue("value")

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:
{"UIAButton":{"@":{"name":"A","label":"A","value":null,"dom":null,"enabled":true,"valid":true,"visible":true,"hint":null,"path":"/0/0/20/0/0/2/1","x":20,"y":233.361328125,"width":40,"height":40}

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: https://github.com/appium/appium/issues?utf8=✓&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.

Thanks, @Christopher_Graham. Will do.

Well this is humbling… I was pointed to the wrong version of the app the whole time. I have no idea how I managed to do that, as I try to be very organized as far as managing and archiving app builds.

My gratitude and sincere apologies to anyone who took the time to help me out with this issue.

2 Likes

I am facing the same issue how to get all the values in the dropdown if the text are in table cells