pywinauto 提供了2种等待方法
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
可选参数:
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() 刚好相反,等待不处于某种状态