前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >windows 桌面GUI自动化- 13.pywinauto 等待方法wait() 和 wait_not()

windows 桌面GUI自动化- 13.pywinauto 等待方法wait() 和 wait_not()

作者头像
上海-悠悠
发布2023-09-11 19:33:32
9850
发布2023-09-11 19:33:32
举报
文章被收录于专栏:从零开始学自动化测试

前言

pywinauto 提供了2种等待方法

  • wait() 等待窗口达到指定状态
  • wait_not() 等待窗口不处于某种状态

wait() 等待

wait() 相关源码

代码语言:javascript
复制
    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:表示重试间隔

使用示例

代码语言:javascript
复制
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() 刚好相反,等待不处于某种状态

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-08-28 10:08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • wait() 等待
  • wait_not()
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档