My project revolves around automating a few task. I open an application, a new 3D file then I do some operation from an access base. I chose pywinauto
and graphic interaction because of the operator needs to do intervention on the software.
My issue is that: the name of the application change when I open a new file. There is the code :
# Search data on the Access Base
cursor = conn.cursor()
cursor.execute("SELECT * FROM [SophieBot_produit] WHERE [SophieBot_produit].[ID PRODUCTION] =?",(prod))
produit_sql = cursor.fetchall()
production, statut, produit_value, nb_element, cas, gamme, sl_tps_open, sl_tps_gen, sl_tps_save = produit_sql[0]
produit = str(produit_value).zfill(8)
# Data work, check with print()
#Connecting to the software
app = application.Application()
app.Connect(path='C:\\myprogram')
# First step everything works
app.SLMAutoFab.menu_select("File -> Open")
app.window_(title_re="Open file.*").Edit.SetEditText('S:\\32 - Articles\\'+ str(gamme) +'\\' + str(cas) +'\\' + str(produit) +'_sup.stl')
app.window_(title_re="Open file.*").Ouvrir.Click()
# New step is to do operation on the software
Now my software application name is changing Myprogram - 3DFile
When you write the new name everything works for example :
app.SLMAutoFab00057389_sup.Part.Click()
But the name of the software change, so I try :
win = 'MyProgram' + str(produit)
app.win.Part.Click()
The code doesn't work and the error message is:
MatchError: Could not find 'win' in 'dict_keys
I'm trying to connect with window(handle)
, and will update the post if it works. Any hints or pointers are greatly appreciated.
You can use a regular expression to match part of the window title.
Check out the
title_re
attribute when callingapp.window()
.Documentation: Window specification
This example matches all windows with a title that starts with "SMLAutoFab":