windows 桌面GUI自动化- 13.pywinauto 等待方法wait() 和 wait_not()
  iKXeBmqdRgYF 2023年11月05日 26 0

前言

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() 刚好相反,等待不处于某种状态



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
iKXeBmqdRgYF