windows 桌面GUI自动化- 13.pywinauto 等待方法wait() 和 wait_not()
前言
pywinauto 提供了2种等待方法
- wait() 等待窗口达到指定状态
- wait_not() 等待窗口不处于某种状态
wait() 等待
wait() 相关源码
def wait(self, wait_for, timeout=None, retry_interval=None):
"""
Wait for the window to be in a particular state/states.
:param wait_for: The state to wait for the window to be in. It can
be any of the following states, also you may combine the states by space key.
* 'exists' means that the window is a valid handle
* 'visible' means that the window is not hidden
* 'enabled' means that the window is not disabled
* 'ready' means that the window is visible and enabled
* 'active' means that the window is active
:param timeout: Raise an :func:`pywinauto.timings.TimeoutError` if the window
is not in the appropriate state after this number of seconds.
Default: :py:attr:`pywinauto.timings.Timings.window_find_timeout`.
:param retry_interval: How long to sleep between each retry.
Default: :py:attr:`pywinauto.timings.Timings.window_find_retry`.
An example to wait until the dialog
exists, is ready, enabled and visible: ::
self.Dlg.wait("exists enabled visible ready")
.. seealso::
:func:`WindowSpecification.wait_not()`
:func:`pywinauto.timings.TimeoutError`
"""
wait_for
可选参数:
- 'exists' 表示窗口存在,是一个有效的句柄
- 'visible' 表示窗口可见
- 'enabled' 表示窗口未被禁用
- 'ready' 表示窗口可见且已启用
- 'active' 表示窗口处于活动状态
timeout:超时时间
retry_interval:表示重试间隔
使用示例
from pywinauto import Application
app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
# 输入内容
win.child_window(title="文本编辑器").set_text("hello world")
# 文件-另存为
win.menu_select('文件(F) -> 另存为(A)...')
# 等待另存为窗口出现
win.child_window(title="另存为", control_type="Window").wait('ready', timeout=5)
wait_not()
与wait() 刚好相反,等待不处于某种状态
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2022-08-24 Flask 学习-15.flask-migrate数据迁移
2022-08-24 2022年第 12期《python接口web自动化+测试开发》课程,9月17号开学!
2021-08-24 python测试开发django-111.模型管理器(models.Manager)
2021-08-24 httprunner 3.x学习20 - jmespath取值特殊字符问题解决
2020-08-24 pytest文档48-切换 base_url 测试环境(pytest-base-url)