denywinarto
denywinarto

Reputation: 45

How to set focus on child window with the same name

OS : windows 11, pywinauto v 0.68

I need to automate a program with these procedures:

  1. Open app
  2. click "particular adjustment mode" button
  3. click "model name" dropdown menu and press L350
  4. Select "printer information check" on listbox
  5. press "check button"
  6. Press "save button"
  7. save as current date on the popup save as menu

The 5th step is the part where i'm stuck, i cannot identify the controls or access the push buttons. whenever i try to identify the controls i get "AccessDenied: [WinError 1400] Invalid window handle. Cannot get process ID from handle."

It's probably because the name of the child window is the same with main window. I checked with swapy and it seems to be the case. There are 2 windows with the same title

duplicatedwindow

from pywinauto.application import Application
import time
import pyinspect as pi


app = Application().start(r"C:\resetter\adjust.exe")
window=app.Dialog

time.sleep(1)
app = Application().connect(title=u'model = (not selected) | port = Auto selection | AdjProg Ver.1.0.0')
app.Dialog.Button3.click()
time.sleep(2)
app = Application().connect(title=u'Adjustment Program')

window.combobox.select(3)
time.sleep(2)

#window.PortComboBox1.select(1)
#time.sleep(2)
app.Dialog.Button3.click()

window.listbox.select(23)
time.sleep(2)
app.Dialog.Ok.click()
time.sleep(4)
app = Application().connect(title=u'model = L350 | port = Auto selection | Adjprog Ver.1.0.0')

This would give error :

ElementNotFoundError: {'title': 'model = L350 | port = Auto selection | Adjprog Ver.1.0.0', 'backend': 'win32', 'visible_only': False}

I have tried

app.Application().child_window(title=u'model = L350 | port = Auto selection | Adjprog Ver.1.0.0').checkbutton.click() 

But it's still the same

Upvotes: 1

Views: 2142

Answers (1)

Arun
Arun

Reputation: 429

From answer and comments found at this post

If there are multiple dialogs with the same name, it's possible to use app.window(title='Dialog name', active_only=True). Or even more detailed choice: app.window(title='Dialog name', found_index=0)

We can also look for text within the dialog box. x in the code will be list of multiple windows with same name.

mywins= pywinauto.findwindows.find_windows(title_re=".*windowTitle")
for handle in mywins:
    app = Application().connect(handle=handle)
    dlg = app.window(handle=handle)

    for x in dlg.descendants():
        print (x.window_text())
        print (x.class_name())

Upvotes: 0

Related Questions