简体   繁体   English

如何从上下文菜单中选择子菜单?

[英]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.我正在尝试使用 pywinauto 从上下文菜单(发送到)中单击子菜单(BTDecoder)项。

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:之后,对于 app.print_control_identifiers,我能够找到如下所示的子菜单:

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?

you should be using backend ='uia' and below is the code you need to use to click on context menu's submenu item你应该使用 backend ='uia' 下面是你需要用来点击上下文菜单的子菜单项的代码

popup_menu = Desktop(backend='uia').window(title="Context")
popup_menu[submenu].click_input()
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()

I was doing the similar kind of work to access the sub context menu for mmc (snap in console) type of app.我正在做类似的工作来访问 mmc(控制台中的管理单元)类型的应用程序的子上下文菜单。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM