Appium can't get text from XCUIElementTypeStaticText

I have iOS app.
There is XCUIElementTypeStaticText element with text inside (“MyTitle”, for example). And this element has accessibility id “titleLabel”.
The problem that Appium can’t get text value from this element. Value, name, label attributes contains acc. id (“titleLabel”), but not actual text.
I tried to get text with code (like .getText()), with Appium Desktop. with some other tools, but no way: all of them returns “titleLabel” as text.
Only Xcode layout inspector displays text value, but in tree view this element is shown like “UILabel - titleLabel”.
All other XCUIElementTypeStaticText (for example, with text “MyText” inside and some acc. id) works correct, and in Xcode the are displayed like “UILabel - MyText” (and I can get text from it as usual).

Are there any other ways to get text from element?

This issue appeared after migrating project to latest Swift version and Xcode 12. And I Appium of latest version.

1 Like

Ask ios dev to fix this problem. Nothing can be done. Or use both ids to find element.

I had the same problem and I was able to fix it by doing this:

I declared with By the element that I want to get text with MobileBy and AccessibilityId, with this method the problem was fixed.

private final By sometext = MobileBy.AccessibilityId("id");
String text = driver.findElement(sometext).getText();

Hmmm, a bit late to this old problem. Just 2 elements are not returning their visible content when I call getText() (Python bindings use an attribute .text to retrieve the same datas)

print(driver.findby_id('account email').text)
> account email

When I look at the DOM in the explorer app, I see same problem the ‘value’ and the ‘label’ are the same content, the label name that I used to locate the element, so I’m basically “seeing” the email text, but XCUITest is not able to retrieve it at all for some reason.

<XCUIElementTypeStaticText type=“XCUIElementTypeStaticText” value=“account email” name=“account email” label=“account email” enabled=“true” visible=“true” accessible=“true” x=“16” y=“47” width=“227” height=“21” index=“1”/>
I am expecting to see the visible text in the app which is my email address. I have also bounced this back to the developers to see if there is something special in how they are setting the control up or populating the control

Still facing this problem in 2024. Anyone got a solution?
Please help. Thanks.