pywinauto做自动测试时,找不到ToolBar工具栏
这个是测试的软件的一个窗口,红框里是工具栏
这个是用spy++查看到的工具栏窗口的信息,看不到工具栏里的菜单
使用UI Spy可以看到工具栏( ControlType:"ControlType.ToolBar"
)底下的菜单,菜单里面还有子菜单
from pywinauto.application import Application
import pywinauto
app = Application().connect(title_re='管理员.*')
win_dgg = app.window(handle=0x000E0BC4)
#找到工具栏窗口
win_dgg.print_control_identifiers()
#打印控件信息
执行结果:
Control Identifiers:
WindowsForms10.Window.8.app.0.2bf8098_r15_ad1 - 'toolStrip1' (L254, T388, R645, B428)
['WindowsForms10.Window.8.app.0.2bf8098_r15_ad1', 'toolStrip1', 'toolStrip1WindowsForms10.Window.8.app.0.2bf8098_r15_ad1']
child_window(title="toolStrip1", class_name="WindowsForms10.Window.8.app.0.2bf8098_r15_ad1")
from pywinauto.application import Application
import pywinauto
app = Application().connect(title_re='管理员.*')
win_dgg = app.window(handle=0x000E0BC4)
tool_bar = win_dgg.ToolBar
#工具栏里的toolbar
tool_bar.Click('查询')
执行了报错
执行结果:
Traceback (most recent call last):
File "C:\Python36-32\lib\site-packages\pywinauto\application.py", line 245, in __resolve_control
criteria)
File "C:\Python36-32\lib\site-packages\pywinauto\timings.py", line 449, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\pythontest\utest\tools.py", line 12, in <module>
tool_bar.Click('查询')
File "C:\Python36-32\lib\site-packages\pywinauto\application.py", line 351, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Python36-32\lib\site-packages\pywinauto\application.py", line 248, in __resolve_control
raise e.original_exception
File "C:\Python36-32\lib\site-packages\pywinauto\timings.py", line 427, in wait_until_passes
func_val = func(*args)
File "C:\Python36-32\lib\site-packages\pywinauto\application.py", line 209, in __get_ctrl
ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
File "C:\Python36-32\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'best_match': 'ToolBar', 'top_level_only': False, 'parent': <win32_element_info.HwndElementInfo - 'toolStrip1', WindowsForms10.Window.8.app.0.2bf8098_r15_ad1, 920516>, 'backend': 'win32'}
初次学习使用pywinauto,看了官方文档还是不太懂,我要怎么样才能找到工具栏并执行点击操作,麻烦大家帮我看看,求指点,感谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论