【问题标题】:Appium and python: find element childAppium 和 python:查找元素子项
【发布时间】:2019-11-02 02:10:36
【问题描述】:

所以我有我正在测试的应用程序,我有这个条件,我有element,我想罚款它的孩子。

我的element

element = elements[0]

子元素是XCUIElementTypeButton(第一个孩子),这是我尝试过的:

son = element.find_element_by_xpath('/XCUIElementTypeButton')

或者

son = element.find_element_by_xpath('//XCUIElementTypeButton')

所以我尝试了这两种工作,但没有收到任何NoSuchElementException。 有什么建议吗?

【问题讨论】:

    标签: python ios appium element


    【解决方案1】:

    您需要将. 添加到您的 XPath 查询中,以便范围相对于当前元素,例如:

    son = element.find_element_by_xpath('./XCUIElementTypeButton')
    

    或使用child axe

    son = element.find_element_by_xpath('child::XCUIElementTypeButton')
    

    或者干脆选择通配符:

    son = element.find_element_by_xpath('child::*')
    

    参考资料:

    【讨论】:

    • 我也可以使用 parent::ElementType 吗?
    • 可以,但它不会返回元素父元素,而不是子元素。
    • 所以如果我想要父母我应该怎么做?
    猜你喜欢
    • 2016-08-30
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 2016-01-21
    • 2019-06-23
    相关资源
    最近更新 更多