Appium和Python:查找子元素

时间:2019-06-19 10:50:04

标签: python ios appium element

因此,我有正在测试的应用程序,并且我有这样的条件:我有element,并且希望对其孩子处以罚款。

我的element

element = elements[0]

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

son = element.find_element_by_xpath('/XCUIElementTypeButton')

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

因此,我尝试了这两项工作,但都没有尝试,因此收到NoSuchElementException。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

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

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

或使用child斧头

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

或只是使用通配符:

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

参考文献:

相关问题