i am trying to access the control identifiers that gets displayed but i am unable to do so. when a Open window gets popped up only the OK and Cancel button i am able to access.. not able to acccess othe options. Please help
How to access the control identifiers in pywinauto
30.9k Views Asked by vj85 At
2
There are 2 best solutions below
0

I get access to the "File Name" in the "Select File to Export"in 3ds max 2015:
I first received information about the dialog box controls with "print_control_identifiers()":
import pywinauto
from time import sleep
pwa_app = pywinauto.application.Application()
# pwa_app.start('{app} {path}\{scene}'.format(app=BINARY_PATH, path=TEST_PATH, scene=TEST_SCENE))
export_dlg_handles = pywinauto.findwindows.find_windows(title=u'Select File to Export', class_name='#32770')
if export_dlg_handles:
export_dlg = pwa_app.window_(handle=export_dlg_handles[0])
export_dlg.print_control_identifiers()
The output:
Control Identifiers:
Static - 'Save &in:' (L172, T146, R258, B159)
'Save &in:' 'Save &in:Static' 'Static' 'Static0' 'Static1'
ComboBox - 'export' (L265, T142, R526, B166)
'ComboBox' 'ComboBox0' 'ComboBox1' 'Save &in:ComboBox'
ToolbarWindow32 - '' (L538, T142, R800, B165)
' Toolbar' 'Toolbar' 'Toolbar0' 'Toolbar1'
ToolbarWindow32 - '' (L172, T171, R259, B705)
'Save &in:Toolbar' 'Toolbar2'
SHELLDLL_DefView - '' (L265, T171, R857, B650)
'SHELLDLL_DefView' 'Save &in:SHELLDLL_DefView'
SysListView32 - 'FolderView' (L265, T171, R857, B650)
'FolderView' 'FolderViewListView' 'ListView'
SysHeader32 - '' (L265, T171, R857, B190)
'Header' 'Save &in:Header'
Static - 'File &name:' (L267, T664, R354, B677)
'File &name:' 'File &name:Static' 'Static3'
ComboBoxEx32 - '' (L361, T659, R762, B681)
'ComboBoxEx' 'File &name:ComboBoxEx'
ComboBox - '' (L361, T659, R762, B681)
'ComboBox2' 'File &name:ComboBox'
Edit - '' (L365, T664, R742, B677)
'Edit' 'File &name:Edit'
Static - 'Save as &type:' (L267, T690, R354, B703)
'Save as &type:' 'Save as &type:Static' 'Static4'
ComboBox - 'Autodesk (*.FBX)' (L361, T687, R762, B708)
'ComboBox3' 'Save as &type:ComboBox'
Button - '&Save' (L782, T659, R857, B682)
'&Save' '&SaveButton' 'Button' 'Button0' 'Button1'
Button - 'Cancel' (L782, T685, R857, B708)
'Button2' 'Cancel' 'CancelButton'
ScrollBar - '' (L848, T699, R865, B716)
'CancelScrollBar' 'ScrollBar'
#32770 - '' (L166, T102, R865, B716)
'#32770' 'Save &in:#32770'
Static - ' ' (L166, T135, R721, B520)
' ' ' Static2' 'Static5'
Static - '' (L715, T165, R715, B188)
' Static3' 'Static6'
Static - 'Thumbnail' (L906, T144, R957, B157)
'Static7' 'Thumbnail' 'ThumbnailStatic'
ComboBox - 'C:\\Users\\stas\\Documents\\3dsMax\\export' (L265, T109, R857, B130)
'ComboBox4' 'History:ComboBox'
Static - 'History:' (L219, T113, R255, B126)
'History:' 'History:Static' 'Static8'
Then i find a strings:
Edit - '' (L365, T664, R742, B677)
'Edit' 'File &name:Edit'
Button - '&Save' (L782, T659, R857, B682)
'&Save' '&SaveButton' 'Button' 'Button0' 'Button1'
'Edit' and 'Button' - names of controls for access.
And I run:
# Endter file name
export_dlg.Edit.SetText(SAVE_FILE_NAME)
# Wait one second
sleep(1.0)
# Click to "Save" button
export_dlg.Button.Click()
For help view the docs:
https://pywinauto.googlecode.com/hg/pywinauto/docs/controls_overview.html
For example 'SetText' for all controls:
SetText(text, pos_start=None, pos_end=None)
Set the text of the edit control
Once you have the dialog open and assigned to a variable then the print_control_identifiers() (also aliased as PrintControlIdentifiers) method should print all the available controls.
The 2nd line output for each control are the different identifiers (though things like spaces and ampersands (&) should be removed.
It is quite possible that Windows Media Player does not use 'standard' Win32 dialogs. But the Open dialog should be easy enough..
Here is the output of my testing of this (with errors and mistakes removed to protect the guilty :))
You can see (hopefully) that the FilenameEdit came from