Pywinauto Doesn't Detect New Window Follow Up Question

Question:

Referring to answer for this question pywinauto does not detect child window

I have a similar issue where I click "New" button and a window appears to key in inputs.
My problem is this new window is not listed in the print_control_identifiers(). Below is my entire code so far right up to the new window pop up

app = Application(backend="uia").connect(title_re="SpectrumPro.*", timeout=20)
dlg = app.window(title_re="SpectrumPro.*")
app.dlg.Edit2.type_keys("XXXXXXX")
app.dlg.Edit.type_keys("YYYYYY")
app.dlg.Login.click()
app.dlg.wait("exists enabled visible ready")
app.dlg.New.click()

After the last line, now I have to get the new child window that had just popped up.
Below is attempt#1 and its error

newDLG = app.window(title="SHOP ORDER Configuration")
dlg.newDLG.print_control_identifiers()
pywinauto.findwindows.ElementNotFoundError: {'title_re': 'SpectrumPro.*', 'backend': 'uia', 'process': 12244}

Below is attempt#2 and its error

newDLG = dlg.window(title="SHOP ORDER Configuration")
app.dlg.newDLG.print_control_identifiers()
pywinauto.findbestmatch.MatchError: Could not find 'newDLG' in 'dict_keys(['Button', 'SpectrumPro WEBButton', 'SpectrumPro WEB',.......])

Attempt#3 is when I tried solution from the reference stack overflow question but same issue

newDLG = app.dlg.child_window(title="SHOP ORDER Configuration")
app.dlg.newDLG.print_control_identifiers()
pywinauto.findbestmatch.MatchError: Could not find 'newDLG' in 'dict_keys(['Button', 'SpectrumPro WEBButton', 'SpectrumPro WEB',....])

When I use Inspect.exe, there are details of the new window buttons, text input, etc. But they don’t exist in the Inspect.exe tree. So I dont know who is the parent of this new window.
Does anyone know how do I connect to this new window that popped up

Asked By: Farid Ibrahim

||

Answers:

I found the solution in case anyone got the same issue

I had to connect the new window using a new application().connect because only this new form window is using win32 backend.

newApp = Application(backend="win32").connect(title_re="SHOP ORDER.*")

After that I was still unable to find the window using method below

newDLG = app.window(title_re="SHOP ORDER Configuration")

I had to use magic attribute names to get the window

newApp.SHOPORDERConfiguration.print_control_identifiers()
Answered By: Farid Ibrahim
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.