【问题标题】:using wait in pywinauto times out but sleep works fine在 pywinauto 中使用 wait 超时,但 sleep 工作正常
【发布时间】:2022-10-24 14:38:23
【问题描述】:

我正在尝试在 Windows 中自动化一些 GUI 的东西。我打开了一个设置窗口,但是在等待它打开后再继续时,它会超时:

from pywinauto import Application

app = Application()
app.start(r"explorer shell:::{05d7b0f4-2121-4eff-bf6b-ed3f69b894d9}")
app.window(title_re=".*Notification Area Icons*").wait("exists", timeout=20)
app = Application(backend="uia").connect(title_re=".*Notification Area Icons*")

main_dlg = app.window(title_re=".*Notification Area Icons*")
main_dlg.print_control_identifiers()

即使超时为 20 秒,它也会超时。但是,如果我用sleep(5) 替换app.window(title_re=".*Notification Area Icons*").wait("exists", timeout=20)(并添加适当的导入)它工作正常。我知道窗口标题是正确的,因为它会在使用 sleep 时打印出控件 ID。我也尝试过使用“存在”和“可见”来等待。我认为其他选项更严格,所以我不确定为什么等待不起作用。

【问题讨论】:

    标签: python pywinauto


    【解决方案1】:

    explorer.exe 进程可能很少。您可以尝试与流程无关的方式:

    from pywinauto import Desktop
    window_wrapper = Desktop(backend="uia").window(title_re=".*Notification Area Icons*").wait("exists", timeout=20)
    print(window_wrapper.process_id())
    # and compare with print(app.process)
    

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2022-06-29
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多