【问题标题】:Appium XPath Selector returns WebDriverExceptionAppium XPath 选择器返回 WebDriverException
【发布时间】:2019-12-30 20:08:48
【问题描述】:

我正在尝试使用 NGTest 框架和 UIAutomator 对 Android 应用执行一些自动化操作。

以下是 UI Automator 的输出 - 我的 XPath 知识不是最热门的,但我尝试使用以下 Java 代码选择相机按钮的父级:

WebElement e = driver.findElement(By.xpath("//android.widget.LinearLayout[@resource-id=com.instagram.android:id/tab_bar']"));

但是这会返回异常:

    org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'

谁能更好地指导我如何使用 XPath 表达式从 UIInspector 向下钻取树?我应该从顶部开始,然后一路向下,还是可以尝试以这种方式抓住孩子?

我也尝试过直接使用边界来抓取相机图标,但这也没有用。

尝试过:

WebElement abc = driver.findElement(By.xpath ("//android.widget.ImageView[contains(@bounds,'[508,2119][571,2131]')']"));
    abc.click();

【问题讨论】:

    标签: xpath appium appium-android


    【解决方案1】:

    我认为您在资源 ID 值的开头缺少引号。 您正在使用:

    WebElement e = driver.findElement(By.xpath("//android.widget.LinearLayout[@resource-id=com.instagram.android:id/tab_bar']"));
    

    它应该是:

    WebElement e = driver.findElement(By.xpath("//android.widget.LinearLayout[@resource-id= 'com.instagram.android:id/tab_bar']"));
    

    This element explorer can really help you locating the elements

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2016-12-02
      相关资源
      最近更新 更多