【问题标题】:unable to locate elements using uiautomator in android native app无法在 android 本机应用程序中使用 uiautomator 定位元素
【发布时间】:2015-10-30 13:16:46
【问题描述】:

使用 Appium 自动化 Android Native 应用程序。
我正在使用 android UIAutomator
识别元素 问题:我有 11 个 android textview 字段,每天都在变化。
我无法读取它们的值,因为所有 11 个字段都具有相同的 classname 和相同的 resource -id。
然后我尝试使用Xpath,但我看到的是当我导航到 textView 时,所有 textviews 都具有相同的索引值,导致所有 11 个 textviews 都具有相同的Xpath。

我正在使用此代码:

List<WebElement> dailychanged=driver.findElementsById("resource-id of your elements");
for (int i = 0 ; i < 11 ; i++){
    System.out.println(dailychanged.get(i).getText());
}

现在我无法识别元素。请建议。

【问题讨论】:

  • 你能分享一下 UIautomator 的快照吗
  • 我正在使用此代码: List dailychanged=driver.findElementsById("resource-id of your elements"); for (int i = 0 ; i
  • 将 list.swipe(SwipeElementDirection.UP, 400) 添加到循环中

标签: android selenium appium


【解决方案1】:

尝试使用@index 属性来引用必要的属性。例如: //android.widget.EditText[@index=0].

编写你的 xpath:

  • 一个。从类开始 //class
  • 乙。添加属性 [@attribute=”attribute_value”]
  • 例如:XPath 来识别文本 8 in 计算器应用程序是“//android.widget.EditText[@index=0]”。我们 可以使用‘文本’、‘内容描述’等属性来写 xpath。

请看全文here。

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 2016-12-22
    • 2017-05-07
    • 2014-03-09
    • 2018-02-14
    • 2018-02-19
    • 2021-11-19
    • 2018-03-15
    • 2017-10-11
    相关资源
    最近更新 更多