【问题标题】:Appium, Android - Finding element inside another elementAppium,Android - 在另一个元素中查找元素
【发布时间】:2016-01-21 11:17:58
【问题描述】:

我正在尝试检查元素是否存在,但是当我们指定它应该在另一个元素内时,appium 似乎忽略了搜索元素。例如:

driver.findElementByAccessibilityId("First element").findElementByAccessibilityId("Second element");

它应该以某种方式工作,因为 Appium 检查器中有一个名为 Locator 的选项,在选择策略并从所选元素选项中选择搜索后,它会找到我期望的内容。

找到这些元素的正确方法是什么?

【问题讨论】:

    标签: android testing selenium-webdriver testng appium


    【解决方案1】:

    您也可以使用 xpath。这种情况的示例 xpath 将如下所示:

    driver.findElement(By.xpath("//*[@accessibility-id='FirstElement']//*[@accessibility-id='FirstElement']"))
    

    第一个元素和第二个元素之间的 // 表示第一个元素是开始搜索第二个元素的基础元素。所以它会在第一个元素的范围内搜索第二个元素

    【讨论】:

    • 我检查了,有多个错误,没有找到元素
    • 能否请您发布所提及页面的页面来源。至少包含以上两个元素的页面源的sn-p?
    【解决方案2】:

    简单的解决方案,但不是下面最干净的:

    我正在使用我认为不允许声明的 TestNG 框架

    private WebElement element= driver.findElementByAccessibilityId("First element").findElementByAccessibilityId("Second element");
    

    简单但不是最好的解决方案是将只有父母声明为:

    @FindBy(name="Parent")
    private WebElement ParentElement;
    

    然后以测试用例为例:

    ParentElement.findElement(By.name("childElement")).isDisplayed())
    

    【讨论】:

      【解决方案3】:

      将第一个元素作为父元素,将第二个元素作为子元素 -

       MobileElement parentButtonList = (MobileElement)driver.findElementById(parentClassIdentifier);
      List<MobileElement> childButtonList = parentButtonList.findElementsById(childClassIdentifier);
      

      【讨论】:

        猜你喜欢
        • 2020-11-25
        • 1970-01-01
        • 1970-01-01
        • 2018-07-28
        • 2020-04-25
        • 1970-01-01
        • 1970-01-01
        • 2015-06-02
        • 2020-07-17
        相关资源
        最近更新 更多