4

I'm trying to wait on a specific window (that I found using the children method from the top window) but it seems that the UIAWrapper doesn't have the wait method.

What can be done to use wait on this window? or maybe convert the UIAWrapper object to the WindowSpecification object?

So for example, I can do this:

app.top_window().wait("enabled")

But I can't do this:

app.top_window().children()[0].wait("enabled")
Drxxd
  • 1,860
  • 14
  • 34
  • 1
    Creating window specification from wrapper is not implemented, but it's interesting feature we're thinking about. This function must take many things into account to create the spec that will match exactly this element. Currently I imagine it as "trial and error method" like this: 1. create some simple spec - if it fails, 2. create some combined spec - if it fails, 3. create more complicated specs until it will find this element, not another one. This procedure can be re-used for future "record-replay" functionality also. – Vasily Ryabov Oct 30 '17 at 17:55
  • 1
    `top_window()` is very simple: it creates the spec like `window(handle=found_hwnd)` but children elements have no native handle very often. There is even no single property that is always present for every element. This makes your feature request not so trivial. – Vasily Ryabov Oct 30 '17 at 17:58
  • @VasilyRyabov The "record-replay" sounds similar to something that I'm doing :).. Anyway, you're saying that it's not so trivial to somehow "wait" on the UIAWrapper elements, right? – Drxxd Oct 31 '17 at 09:35
  • 1
    Yes, UIAWrapper is created for already existing element, but Window Specification can be created for the element that will appear in the future or was already closed. – Vasily Ryabov Oct 31 '17 at 13:44
  • 1
    So UIAWrapper does exist, nothing to wait. – Vasily Ryabov Oct 31 '17 at 13:45
  • 1
    @VasilyRyabov But even if the element exists, it can still be disabled or inactive. So I could use 'wait("enabled")' on it if it would be possible – Drxxd Oct 31 '17 at 18:01
  • Yes, it makes sense. But again it's hard to separate WindowSpecification.wait() and UIAWrapper.wait() because wrapper can be created implicitly. So user won't know which wait() method is really called. – Vasily Ryabov Oct 31 '17 at 20:29
  • Maybe waiting for "exist" makes sense for WindowSpec only. It simplifies internal implementation, but requires some architectural changes. I'd plan it for next major release 0.7.0. Will post a workaround a bit later. Typing from phone... – Vasily Ryabov Nov 01 '17 at 04:23

1 Answers1

2

Let's combine all the comments. This feature request could be implemented in next major release pywinauto-0.7.0. See issue #434.

Current workaround:

from pywinauto.timings import wait_until

wrapper = app.top_window().children()[0]
wait_until(timeout=5, retry_interval=0.1, wrapper.is_enabled)
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78