PyWinAuto - Xpath 之类的识别 [英] PyWinAuto - Xpath like identification

查看:80
本文介绍了PyWinAuto - Xpath 之类的识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找如何根据 xpath 在 GUI 中搜索对象的方法.申请鉴定的一部分我的 xpath 如下:

I'm looking for way how to search objects in GUI according to xpath. part of identification of application I have xpath as follows:

./pane[0]/pane[0]/pane[1]/pane[0]/pane[1]/pane[0]/pane[0]/pane[0]/text[0]/编辑[0]

./pane[0]/pane[0]/pane[1]/pane[0]/pane[1]/pane[0]/pane[0]/pane[0]/text[0]/edit[0]

这应该(如果我在那里没有问题)指向应用程序元素树中选定的 EDIT.

This should (if i have no problem there) point to selected EDIT in application element tree.

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

I tried to use this xpath to identify items like this

#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)

我现在还没有编写递归函数,但也许我走错了路.

I don't have recursive function written by now, but maybe I'm going the wrong way.

那么问题是,有没有什么办法可以像样式一样恢复xpath中元素的路径?

So the question is, is there any way how to recover path to element in xpath like style?

谢谢

推荐答案

对于第一种情况,它应该是这样的:

For the first case it should look so:

first = top.child_window(control_type="Pane", depth=2)
# a bit confusing, will bind to depth=1 in future major release.

对于第三种情况是,ctrl_index 在按其他条件过滤之前使用.如果您需要先应用搜索条件,然后从过滤后的小列表中进行选择,还有另一个适合您情况的参数:found_index.

For third case yes, ctrl_index is used before filtering by other criteria. If you need to apply search criteria first and then choose from small filtered list, there is another param suitable for your case: found_index.

应该改成这样:

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

这篇关于PyWinAuto - Xpath 之类的识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆