SWAPY icon indicating copy to clipboard operation
SWAPY copied to clipboard

Reuse `app` variable

Open moden-py opened this issue 10 years ago • 3 comments

Reuse app variable for one process owned different top level windows. One app may be used for all windows owned by one process. For instance:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()
window = app.Dialog
window.Wait('ready')
button = window.OK
button.Click()

app.Kill_()

Now the same actions code looks:

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
notepad = app.Notepad
notepad.Wait('ready')
menu_item = notepad.MenuItem(u'&Help->&About Notepad')
menu_item.Click()

app2 = Application().Start(cmd_line=u'"C:\\Windows\\system32\\notepad.exe" ')
window = app2.Dialog
window.Wait('ready')
button = window.OK
button.Click()
button.Click()

app2.Kill_()
app.Kill_()

Restarting the same application is probably not the thing you expect.

moden-py avatar Oct 25 '15 12:10 moden-py

In case the second window opens after some action on the first one, you should refresh the objects tree to add new windows. Before fix "Reuse app" issue, a "safe refresh" should be applied. Now all the counters are reset after the object browser refresh.

moden-py avatar Oct 25 '15 16:10 moden-py

Depends on #66

moden-py avatar Oct 27 '15 19:10 moden-py

i download the code and how to run manually

GopinathB-Hexaware avatar Dec 07 '17 07:12 GopinathB-Hexaware