'How to select a sub menu from a context menu?
I am trying to click on a sub menu(BTDecoder) item from a context menu(send to) using pywinauto.
I could click on the menu item from context list and click on it. But when i try to click on sub menu, its not happening. its showing there is no item like that.
Here is my code :
path=os.path.realpath(path)
os.startfile(path) # open the folder named "FW"
app = pywinauto.Desktop(backend='uia').window(best_match='FW')
win = app.window(title_re='WRT_FW_27_12_2018_11_19_59_000001')
win.click_input(button='left')
win.click_input(button='right') # right click on one file listed there
app1 = pywinauto.Desktop(backend='uia').window(best_match='ContextMenu',top_level_only = True)
win1 = app1.window(title_re="Send to")
win1.click_input() # click on "Send to" context menu
app.print_control_identifiers()
app2 = pywinauto.Desktop(backend='uia').window(best_match='ContextMenuItem',top_level_only = True)
win2 = app2.window(title_re="BTDecoder")
win2.click_input() # trying to click on sub menu item called "BTDecoder" which not happening.
after clicking the "send to" contextmenu, sub menu context is appeared. after that for app.print_control_identifiers, am able to find the sub menu as shown below:
Dialog - 'FW' (L85, T151, R1250, B728)
['FW', 'FWDialog', 'Dialog', 'FW0', 'FW1']
child_window(title="FW", control_type="Window")
|
| Menu - 'Send to' (L31, T101, R468, B573)
| ['Menu', 'Send toMenu', 'Send to', 'Menu0', 'Menu1']
| child_window(title="Send to", control_type="Menu")
| |
| | MenuItem - 'Bluetooth device' (L34, T104, R465, B128)
| | ['Bluetooth device', 'MenuItem', 'Bluetooth deviceMenuItem', 'MenuItem0', 'MenuItem1']
| | child_window(title="Bluetooth device", auto_id="31011", control_type="MenuItem")
| |
| | MenuItem - 'BT Decoder CLI' (L34, T128, R465, B150)
| | ['BT Decoder CLI', 'BT Decoder CLIMenuItem', 'MenuItem2']
| | child_window(title="BT Decoder CLI", auto_id="31012", control_type="MenuItem")
| |
| | MenuItem - 'BT FW Trace Viewer' (L34, T150, R465, B172)
| | ['BT FW Trace ViewerMenuItem', 'MenuItem3', 'BT FW Trace Viewer']
| | child_window(title="BT FW Trace Viewer", auto_id="31013", control_type="MenuItem")
| |
| | MenuItem - 'BTDecoder' (L34, T172, R465, B194)
| | ['BTDecoderMenuItem', 'MenuItem4', 'BTDecoder']
| | child_window(title="BTDecoder", auto_id="31014", control_type="MenuItem")
| |
| | MenuItem - 'Compressed (zipped) folder' (L34, T194, R465, B216)
| | ['Compressed (zipped) folderMenuItem', 'MenuItem5', 'Compressed (zipped) folder']
| | child_window(title="Compressed (zipped) folder", auto_id="31015", control_type="MenuItem")
| |
| | MenuItem - 'Desktop (create shortcut)' (L34, T216, R465, B238)
| | ['Desktop (create shortcut)', 'Desktop (create shortcut)MenuItem', 'MenuItem6']
| | child_window(title="Desktop (create shortcut)", auto_id="31016", control_type="MenuItem")
```````````````````````````````````````````````````
how to click on this sub menu item?
Solution 1:[1]
you should be using backend ='uia' and below is the code you need to use to click on context menu's submenu item
popup_menu = Desktop(backend='uia').window(title="Context")
popup_menu[submenu].click_input()
Solution 2:[2]
path=os.path.realpath(path)
os.startfile(path) # open the folder named "FW"
app = pywinauto.Desktop(backend='uia').window(best_match='FW')
win = app.window(title_re='WRT_FW_27_12_2018_11_19_59_000001')
win.click_input(button='left')
win.click_input(button='right') # right click on one file listed there
app1 = pywinauto.Desktop(backend='uia').window(best_match='ContextMenu',top_level_only = True)
win1 = app1.window(title_re="Send to")
win1.click_input()
Add the below lines
app2 = Desktop(backend='win32')
app2.PopupMenu.menu_item('BTDecoder').click_input()
Solution 3:[3]
I was doing the similar kind of work to access the sub context menu for mmc (snap in console) type of app.
I was able to interact with the sub context menu by using below line of code-
# To access context menu item
app.ContextMenu.child_window(title='Send To', control_type='MenuItem').click_input()
# To access the sub context menu use the PopupMenu control type.
app.PopupMenu.child_window(title='BTDecoder', control_type='MenuItem').click_input()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Waterworks |
Solution 2 | Pramod |
Solution 3 | Dev |