#StackBounty: #python #pywinauto GUI Automation of policy change for logoff button. pywinauto.findwindows.ElementNotFoundError: error. …

Bounty: 50

enter image description here

I am automating the steps to change the policy for the logoff button. The steps involved are:

  1. Open Local Group Policy using gpedit.msc

  2. Select “Start Menu and Taskbar” from the dropdown in User Configuration > Administrative Template from the left pane

  3. In the right pane, double click on “Change Start Menu power button”

  4. Select the radio button “Enabled”

  5. From the dropdown menu of options: Select “Log Off”

I have gotten through the third step, but I have a problem in mapping the “Change Start Menu Power Button” from the second step. My code is as below:

from pywinauto import Application

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

Admin_template = app.LocalGroupPolicyEditor.child_window(title="User 
Configuration", control_type="TreeItem").child_window(title="Administrative 
Templates", control_type="TreeItem") # since there are same templates 
Admin_template.double_click_input() # it expands the subtree
#Admin_template.dump_tree()

Start_menu = Admin_template.child_window(title="Start Menu and Taskbar", 
control_type="TreeItem").double_click_input()
Start_menu.dump_tree()
#Admin_template.child_window(title="Start Menu and Taskbar", 
control_type="TreeItem").dump_tree()

#Change_start_menu = Start_menu.child_window(title="Change Start Menu power 
#button", control_type="MenuItem").double_click_input()
#Change_start_menu.dump_tree()

I have trouble in finding and mapping the elements in the right pane. Also, when I use Start_menu.dump_tree(), there are only “Notification” elements shown. However, the rest, which includes “Change Start Menu power button,” is what I’ll be double clicking next.

enter image description here

I appreciate the help. Thanks.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.