繁体   English   中英

NativeScript-Dev-Appium:UIElement.text()/ UIElement.getAttribute(“ value”)返回automationText而不是显示的文本

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

我正在使用NativeScript-Dev-Appium@5.0.0,并希望检查标签上显示的文本。 我已将AutomationText属性分配给,并使用Driver.findElementByAccessibilityId(automationTextValue)来获取元素。 找到该元素,但是当我尝试在其上使用UIElement.text()/ UIElement.getAttribute(“ value”)时,它将返回automationText属性的值,而不是实际显示的文本。 还有其他方法可以执行,因为我找不到任何方法。

不幸的是,这是NativeScript本身的局限性,因为当使用automationText属性时,它将设置元素的所有属性,例如值,名称,标签等。我建议您将相同的文本设置为automationText属性,然后可以访问或使用如下所示测试元素:

  1. 使用XPath:
const el = await driver.findElementByXPath("//*[@name=\"My automation text\"]");
  1. 仅适用于Android
const el = await driver.findElementByText("My automation text");
const text =  await el.getAttribute("text");
  1. 使用imageVerification类型,例如:
await driver.compareRectangle
await driver.compareElement
await driver.compareScreen 

这非常方便,但是这里的缺点是,这有时需要更高的维护。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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