【问题标题】:Appium giving null response when trying to find it inside a scroll view using xpathAppium 在尝试使用 xpath 在滚动视图中找到它时给出空响应
【发布时间】:2021-01-25 05:23:30
【问题描述】:

我目前是 appium 的新手。 我正在尝试单击我的应用程序的滚动视图中的一个项目,其中元素由 xpath 找到。

MobileElement el11 = (MobileElement) driver.findElementByXPath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[4]/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[7]/android.view.ViewGroup[2]/android.widget.TextView");
        System.out.println(el11.getText().equalsIgnoreCase("View More"));
        el11.click();
        System.out.println("Tap performed");

在第一个 syso 声明中我得到了真实。并且 seocnd syso 语句正在被执行。

但在 appium 服务器日志中。 click() 函数返回 null。当我尝试点击 appium 检查器中的项目时,点击会导致另一个页面的导航。

请帮忙

【问题讨论】:

    标签: testng appium appium-android testng-eclipse appium-desktop


    【解决方案1】:

    要点击可滚动视图中的任何元素,最好使用 UIAutomator 选择器,首先找到它并将其滚动到视口可见区域,然后您可以点击。

    MobileElement el11 = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
             ".scrollIntoView(new UiSelector().text(\"View More\"))"));
    el11.click();
    

    附带说明,按文本搜索是一种不好的方法,因为您可能会将其放在不同的标签中。尽可能使用资源 ID

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-11
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 2019-04-24
      • 2019-04-28
      相关资源
      最近更新 更多