Pywinauto menu selection error - Wireshark

I am very new to windows automation.I am automating wireshark using autopy.Now i need to open a file wireshark.I dont have swapy tool.I also dot want to do it in pyshark.I just want to try only in pywinauto.so i tried this way:

from pywinauto import application

print("Starting the proogram")
app=application.Application()
app.start_(r"C:\Program Files\Wireshark\Wireshark.exe")
win = app.window_(title_re = ".*Wireshark Network Analyzer.*")
win.MenuSelect("File->Open")

But i get this below error :

pywinauto.findwindows.WindowNotFoundError

Kindly help me out here with this guys.Thanks in advance

Upvotes: 2

Views: 720

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 10000

As I can see WireShark is starting up several seconds. You need waiting main window longer than default timeout (5 sec.).

 win.wait('ready', timeout=15)

"Software Update" window can also be handled if it pops up:

if app.SoftwareUpdate.exists(timeout=10):
    app.SoftwareUpdate.SkipThisVersion.click()
    app.SoftwareUpdate.wait_not('visible') # just to make sure it's closed

win.wait('ready', timeout=15)

EDIT (2019, Jan, 21): the latest version of WireShark is built on Qt5 and current pywinauto example is maintained in the repo: examples/wireshark.py.

(old part of the answer below) But in any case pywinauto doesn't support GDK widgets (even Windows UI Automation API doesn't support GDK apps). Menu is not available to pywinauto or UIA-based tools. You can deal with WireShark using workarounds only like so:

win.type_keys('%F{ENTER}') # Alt+F, Enter (it calls "&File->&Open" menu)
app.WiresharkOpenCaptureFile.FilenameEdit.set_edit_text('I can set text here')
app.WiresharkOpenCaptureFile.Open.click()
app.WiresharkOpenCaptureFile.wait_not('visible')

"Open" dialog is standard variation of Windows Open/Save dialog and pywinauto supports many controls on it.

To check which dialog is supported well by pywinauto use print_control_identifiers() method:

win.print_control_identifiers() # prints nothing
app.WiresharkOpenCaptureFile.print_control_identifiers() # prints a lot of controls

Upvotes: 3

Related Questions