3

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?

rpanai
  • 12,515
  • 2
  • 42
  • 64
Trilok M
  • 681
  • 7
  • 21

1 Answers1

1

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.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • File "step32.py", line 11, in print_servers.child_window(title="G23XNQ2E(local)", control_type="TreeItem").right_click_input() File "C:\Python37\lib\site-packages\pywinauto\application.py", line 352, in __getattribute__ ctrls = self.__resolve_control(self.criteria) – Trilok M Mar 03 '19 at 04:14
  • File "C:\Python37\lib\site-packages\pywinauto\application.py", line 249, in __resolve_control raise e.original_exception File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 431, in wait_until_passes func_val = func(*args, **kwargs) – Trilok M Mar 03 '19 at 04:15
  • File "C:\Python37\lib\site-packages\pywinauto\application.py", line 210, in __get_ctrl ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria)) File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': 'G23XNQ2E(local)', 'control_type': 'TreeItem', 'top_level_only': False, 'parent': , 'backend': 'uia'} – Trilok M Mar 03 '19 at 04:15
  • any comments on the error in my system. Is it system dependent ? – Trilok M Mar 03 '19 at 04:16
  • the code opens the first Dialog and waits for some time to give the above error. – Trilok M Mar 03 '19 at 04:19
  • Sorry, I have mistyped the title from the screenshot (I have another hostname on my local PC, of course). Now added missed letter `Z` into the title and edited the answer. Please re-check. – Vasily Ryabov Mar 03 '19 at 22:09
  • Also added one more commented line as alternative way with `title_re` (didn't check it yet). – Vasily Ryabov Mar 03 '19 at 22:12