How to select a sub menu from a context menu?

偶尔善良 提交于 2020-03-05 05:52:58

问题


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?

回答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()


来源:https://stackoverflow.com/questions/55628598/how-to-select-a-sub-menu-from-a-context-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!