【问题标题】:NativeScript-Dev-Appium : UIElement.text() / UIElement.getAttribute("value") returns the automationText instead of the text displayedNativeScript-Dev-Appium : UIElement.text() / UIElement.getAttribute("value") 返回自动化文本而不是显示的文本
【发布时间】:2019-02-21 00:37:22
【问题描述】:

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

【问题讨论】:

  • 您介意提供您正在使用的确切代码吗?我不确定您是使用 {N} 提供的包装库还是直接访问 appium 驱动程序。
  • 你能发布你从中获取文本的元素的html

标签: appium nativescript


【解决方案1】:

不幸的是,这是 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 

这很方便,但缺点是在某些时候需要更多的维护。

【讨论】:

    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 2019-08-20
    相关资源
    最近更新 更多