所以我有我正在测试的应用程序,我有这个条件,我有element
,我想罚款它的孩子。
我的element
:
element = elements[0]
子元素是XCUIElementTypeButton
(第一个孩子(,这是我尝试过的:
son = element.find_element_by_xpath('/XCUIElementTypeButton')
或
son = element.find_element_by_xpath('//XCUIElementTypeButton')
所以我尝试了这两种方法,但这些工作都没有收到,NoSuchElementException
收到。有什么建议吗?
您需要
将.
添加到 XPath 查询中,以便范围相对于当前元素,如下所示:
son = element.find_element_by_xpath('./XCUIElementTypeButton')
或使用child
斧头
son = element.find_element_by_xpath('child::XCUIElementTypeButton')
或者干脆选择通配符:
son = element.find_element_by_xpath('child::*')
引用:
- XPath 语法
- XPath 轴
- XPath 运算符和函数