Skip to content Skip to sidebar Skip to footer

How To Right Click On A Folder And Select From Context Menu Using Pywinauto?

I'm writing automation tests for a cloud syncing desktop application. The problem I'm facing is that I cannot select a sub-folder from a window and I cannot select an option from c

Solution 1:

To continue vasiliy ryabov's answer. It can be accomplished with the latest UIA branch of pywinauto. Let's say you have a Video folder opened and you try to right click on a sub-folder called My Home Videos. When a context menu is popped up we just click on Open menu item:

dsk = pywinauto.Desktop(backend='uia')
explorer = pywinauto.Application().Connect(path='explorer.exe')

# chain actions: set focus and right click after that
explorer.Video.MyHomeVideos.set_focus().click_input(button='right')

# Here we get to the popup menu
dsk.Context.Open.click_input()

Solution 2:

(WARNING: for early testing of UIA branch of pywinauto; will replace the answer after pywinauto 0.6.0 is out)

If you're familiar with Git, just clone the main repo, switch to UIA branch, install comtypes with pip install comtypes and then install pywinauto (UIA branch) by python setup.py install.

Explorer should be run with app = Application(backend='uia').start("explorer.exe"). Other things would look almost the same except PEP8 names for methods (click_input instead of ClickInput etc.).

For the context menu you can use the following (because MenuWrapper is not ready for UIA)

app2 = Application(backend='native').connect(process=app.process)
app2.PopupMenu.Wait('visible', timeout=15).Menu().GetMenuPath("item name")[0].Click()`

ListViewWrapper is implemented for UIA very recently. Any feedback is appreciated.


EDIT1: I could take list of files so (assume apps/MFC_Samples folder is open):

explorer = pywinauto.Application(backend='uia').connect(path='explorer.exe')
explorer.MFC_Samples.ItemsView.children_texts()[1:]

Output:

[u'x64', u'BCDialogMenu.exe', u'CmnCtrl1.exe', u'CmnCtrl2.exe', u'CmnCtrl3.exe',
u'CtrlTest.exe', u'mfc100u.dll', u'RebarTest.exe', u'RowList.exe', u'TrayMenu.exe']

I'll prepare more detailed example later.

Post a Comment for "How To Right Click On A Folder And Select From Context Menu Using Pywinauto?"