Trilok M
Trilok M

Reputation: 729

GUI automation using pywinauto python. Attribute error , menu_select() missing error in uaicontrols.py

I'm tring to automate a windows gui mouse click of a check box in properties of a printer. I get to this by starting print management mmc right clicking on "G23XnQ2E (local)" from "Print Servers" drop down in the left pane and selecting properties, switching to "security tab" and i finally want to select the checkbox against manage printer option "

I get to this by starting print management mmc, right clicking on "G23XnQ2E (local)" from "Print Servers" drop down in the left pane and selecting properties, switching to "security tab" and i finally want to select the checkbox against manage printer option. This can also be achieved by directly clicking on the action menu and selecting properties, provided that i have selected "G23XnQ2E (local)" from the printer servers.

I have tried all the possible ways that I can thing of but always end up getting the many errors like "raise AttributeError", "menu_select", "select()", "click()" - "missing".

my code is like say:

from pywinauto import Application

Application().start(r'mmc printmanagement.msc') 
app = Application(backend="uia").connect(path='mmc.exe')
app.PrintManagement.dump_tree() 
app.dialog.pane1.pane5.pane6.menu.menu_select("Action -> Properties")
#app.dialog.menu_select("Action -> Properties")
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.select()
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.click()

How to fix the problem?

Upvotes: 4

Views: 1478

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 10000

menu_select is good for main menu like "File->Open". It doesn't work for popup/context menus. This is my code working on my PC (name of print server has been changed to yours):

from pywinauto import Application

Application().start(r'mmc printmanagement.msc') 
app = Application(backend="uia").connect(path='mmc.exe')
#app.PrintManagement.dump_tree()

print_servers = app.PrintManagement.child_window(title="Print Servers", control_type="TreeItem")
print_servers.select() # it expands the subtree

# call popup menu
print_servers.child_window(title="G23XZNQ2E (local)", control_type="TreeItem").right_click_input()

# alternative way to call popup menu
#print_servers.child_window(title_re=".*\(local\)$", control_type="TreeItem").right_click_input()

# select "Properties..." menu item
app.ContextMenu.child_window(title="Properties...", control_type="MenuItem").select()

#app.PrintManagement.Print_Server_Properties.dump_tree()
app.PrintManagement.Print_Server_Properties.TabControl.select('Security')
app.PrintManagement.Print_Server_Properties.child_window(title="Allow Manage Printers", control_type="CheckBox").toggle()

All child_window specifications have been copied from dump_tree() outputs. Some windows are children of main window, but context menu is a top level one. This is not a documented experience, but we're working on a recorder feature planned this year as Beta. So it will be much easier to generate a script without thinking about hierarchy structure so much.

Upvotes: 1

Related Questions