Reputation: 45
OS : windows 11, pywinauto v 0.68
I need to automate a program with these procedures:
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
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
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