【问题标题】:Appium clicking dynamic list itemAppium点击动态列表项
【发布时间】:2019-07-23 06:39:17
【问题描述】:

我正在尝试自动单击包含特定文本的动态可滚动列表项。列表项的文本正在使用 api 调用,它可能/将根据 api 响应进行更改。

例如,假设我有 3 个列表项,例如苹果、芒果和香蕉。如果我想点击包含文本香蕉的项目,我该怎么做?

我的 Appium 桌面检查器我的动态列表的 xml 文件如下所示

<android.view.ViewGroup content-desc="Dashboard_lv_Container">
 <android.view.ViewGroup>
  <android.widget.ListView content-desc="Dashboard_lv">
   <android.widget.LinearLayout>
    <android.view.ViewGroup>
     <android.widget.FrameLayout content-desc="item_1">
      <android.view.ViewGroup>
       <android.view.ViewGroup>
          <android.widget.TextView>
       <android.view.ViewGroup>
          <android.widget.ImageView>
   <android.widget.LinearLayout>
    <android.view.ViewGroup>
     <android.widget.FrameLayout content-desc="item_2">
      <android.view.ViewGroup>
       <android.view.ViewGroup>
         <android.widget.TextView>
       <android.view.ViewGroup>
         <android.widget.ImageView>

我想选择 android.widget.TextView 中包含特定文本的项目。我怎样才能做到这一点?

【问题讨论】:

  • 您的代码尝试?错误堆栈跟踪?
  • 我使用 **UiSelector.text('banana')" 为 android 解决它。

标签: selenium automated-tests appium appium-android


【解决方案1】:

我使用 UiSelector

解决了这个问题
try {
     MobileElement element=driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"banana\")"));
    element.click();
}catch (org.openqa.selenium.NoSuchElementException e){
    System.out.println("Element not found");
}

对于可滚动列表,我使用 UiScrollable 说明

try {
     MobileElement element=driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(\"new UiSelector().description(\"Dashboard_lv\")\").getChildByText(\"new UiSelector().text(\"banana\")\")"));
    element.click();
}catch (org.openqa.selenium.NoSuchElementException e){
    System.out.println("Element not found");
}

【讨论】:

    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 2019-03-10
    • 2018-01-25
    • 2016-03-23
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多