Python PyWinAuto-Xpath类标识

Python PyWinAuto-Xpath类标识,python,ui-automation,pywin32,pywinauto,Python,Ui Automation,Pywin32,Pywinauto,我正在寻找如何根据xpath在GUI中搜索对象的方法。应用程序标识的一部分 我的建议如下: /窗格[0]/窗格[0]/窗格[1]/窗格[0]/窗格[1]/窗格[0]/窗格[0]/窗格[0]/文本[0]/编辑[0] 这应该(若并没有问题的话)指向应用程序元素树中的选定编辑。 我尝试使用这个xpath来标识这样的项 #app is the application under test, this is working correctly top = app.top_window() first =

我正在寻找如何根据xpath在GUI中搜索对象的方法。应用程序标识的一部分 我的建议如下:

/窗格[0]/窗格[0]/窗格[1]/窗格[0]/窗格[1]/窗格[0]/窗格[0]/窗格[0]/文本[0]/编辑[0]

这应该(若并没有问题的话)指向应用程序元素树中的选定编辑。

我尝试使用这个xpath来标识这样的项

#app is the application under test, this is working correctly
top = app.top_window()
first = top.child_window(control_type="Pane")
print first  #here is first problem:  This will find all the child_windows, no just the direct children, without depth search  (is it possible to just search particular direct childrens, without deeper search?)
first = top.child_window(control_type="Pane", ctrl_index=0)
#this is much better

second = first.child_window(control_type="Pane", ctrl_index=0)
print second
#this is working, i'm looking for [0] indexed Pane under first found element

third = second.child_window(control_type="Pane", ctrl_index=1)
print third
# we have another problem , the algorithm is depth first, so ctrl_index=1 is not referencing to '2nd child of element named second', but instead to the first element of first pane, founded under 2nd element. (I'm looking for wide first algorithm)
我现在还没有编写递归函数,但可能我走错了方向

所以问题是,有没有办法以类似xpath的方式恢复元素的路径


感谢第一个案例,它看起来应该是这样的:

first = top.child_window(control_type="Pane", depth=2)
# a bit confusing, will bind to depth=1 in future major release.
对于第三种情况“是”,在按其他条件过滤之前使用
ctrl\u index
。如果您需要先应用搜索条件,然后从较小的筛选列表中进行选择,则有另一个参数适合您的情况:
found\u index

应将其更改为:

third = second.child_window(control_type="Pane", found_index=1)

我的回答有帮助吗?