簡體   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