Python-UIAutomation-for-Windows
Python-UIAutomation-for-Windows copied to clipboard
Question: 重启后某客户端后 找不到元素
环境:python3.6
uiautomation 1.1.8
某银行网银客户端
目的: 我们制作了一个拾取程序,来进行uia拾取。并调用uiautomation模块,根据拾取结果, 实现 点击某银行网银客户端初始页面的账户输入框
问题描述: 打开银行网银客户端,根据拾取结果,可以找到元素并点击。 此时如果重启客户端,根据拾取结果,则点击失败。 如果再次拾取(可以确认2次拾取结果一致),运行程序,则点击成功。 尝试在打开客户端后,等待10秒,也无法找到元素,点击失败。 尝试SetGlobalSearchTimeOut(30) 也找不到元素。
元素的拾取结果是: {"selector":[{"ControlType":"编辑","ControlTypeID":"0xC354","Index":"1"}, {"ControlType":"","ControlTypeID":"0xC369","Index":"2"}, {"ControlType":"文档","ControlTypeID":"0xC36E","Index":"1"}, {"ControlType":"窗口","ControlTypeID":"0xC370","Index":"1"}, {"ControlType":"窗格","ControlTypeID":"0xC371","Index":"1"}, {"ControlType":"窗格","ControlTypeID":"0xC371","Index":"2"}]} 可以确认每次打开客户端,输入框的拾取结果不会变化。
报错信息: File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2613, in Click File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2585, in MoveCursor File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2571, in BoundingRectangle File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2489, in Element File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2474, in Refind File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2443, in Exists File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2489, in Element File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2474, in Refind File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2443, in Exists File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2489, in Element File "D:\Program Files\Python\lib\uiautomation\uiautomation.py", line 2483, in Refind LookupError: Find Control Time Out: {ControlType: DocumentControl, }
打扰下~~~ 请教这种情况出现的可能原因,print("Thanks").
桌面上打开的应用数小于5个。 searchDepth尝试了1、2、5、10、30,都是一样的效果。 网银客户端 最小化,显示在任务栏中。 而不是在右侧托盘中。
问题仍继续存在,只是找到了一个临时解决方案,在这记录下,也请开发者可以稍微给点思考建议,为什么会发生这种事情。。。

在执行点击前,执行下列代码
import uiautomation as uia
wc = uia.WindowControl(searchDepth=2, Name='xxxxxx银行网银客户端')
c = wc.EditControl(Name='请输入登录名')
uia.EnumAndLogControl(c, 3, True, True)
接下来是log:
ControlType:
EditControl
ClassName:
AutomationId:
Rect:
(1331, 600, 1556, 634)
Name:
请输入登录名
Handle:
0x0(0)
Depth:
0
Value:
请输入登录名
SupportedPattern:
InvokePattern
LegacyIAccessiblePattern
ScrollItemPattern
TextPattern
ValuePattern