简体   繁体   中英

NativeScript-Dev-Appium : UIElement.text() / UIElement.getAttribute(“value”) returns the automationText instead of the text displayed

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.

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:

  1. Using XPath:
const el = await driver.findElementByXPath("//*[@name=\"My automation text\"]");
  1. For Android only
const el = await driver.findElementByText("My automation text");
const text =  await el.getAttribute("text");
  1. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM