Get text displayed on label
codermannn opened this issue · 2 comments
I am using NativeScript-Dev-Appium@5.0.0 and wish to check for the text displayed on a label. I have automationText property assigned to the and use Driver.findElementByAccessibilityId(automationTextValue) to get the element. The element is found, but when I try to use the UIElement.text() / UIElement.getAttribute("value") on it, it returns the value of the automationText attribute instead of the actual displayed text. Is there any other method to do it because I can't find any.
Here's the stackoverflow link to the issue
unfortunately, this is a limitation of NativeScript itself since when the automationText property is used, it will set all properties of the element like value, name, label etc. I would suggest you set the same text to automationText property and then you can access or test the element using something like this:
Using XPath:
const el = await driver.findElementByXPath("//*[@name=\"My automation text\"]");
For Android only
const el = await driver.findElementByText("My automation text"); const text = await el.getAttribute("text");
Use imageVerification types like:
await driver.compareRectangle
await driver.compareElement
await driver.compareScreen
Which is very convenient but the cons here is that this will require higher maintenance at some point.
Just to be clear, there is no way to do something like await el.getAttribute("text");
on iOS? Or for that matter, await el.getAttribute("myCustomAttribute?");