首页 > 解决方案 > 获取 Wireshark PacketList 窗口上 vScroll 向下箭头中间的 POINT

问题描述

#!/usr/bin/env python
# # myGUI7.py   # use pywinauto to start Wireshark
# Visual Studio Code is Run as Administrator 

import os
import sys

import pywinauto 
from pywinauto.application import Application

# which PyQt5 is needed to be imported?
#from PyQt5 import QtCore, QtWidgets
#from PyQt5.QtGui import *
#from PyQt5.QtWidgets import QAbstractSlider

def process_GUI(pname, fname): 
    # start Wireshark -- it uses Qt5, ergo backend = uia
    app = Application(backend="uia").start(r"C:\\Program Files\\Wireshark\\Wireshark.exe ")
    if app.SoftwareUpdate.exists(timeout=5):
        app.SoftwareUpdate.SkipThisVersion.click()
        app.SoftwareUpdate.Wait_Not('visible') #make sure it is closed
    ##app['The Wireshark Network Analyzer'].print_control_identifiers()

    # open any pcapng file
    win = app["The Wireshark Network Analyzer"]
    win.wait('ready', timeout=5)
    win.type_keys('%F{ENTER}') # Alt+F, Enter (it calls "&File->&Open" menu)
    app.Dialog2.FilenameEdit.set_edit_text(pname + fname)
    app.Dialog2.Open4.click()
    win = app[fname]
    win.wait('ready', timeout=5)
    ##win.print_control_identifiers()

    # get the Packet list window
    PL = win["Packet list"]  # it is a TreeView object  
 
    # how do I get the POINT in middle of Down arrow of vScroll on PL?

# = = = = = = =
if __name__ == '__main__':
    # use path/file of any pcapng that has been saved
    path_name = "C:\\H_Paul\\ws\\"
    file_name = "ws-aug22a_SOsample.pcapng"
    guiReturn = process_GUI(path_name, file_name)
    sys.exit(0)

标签: pythonwiresharkpywinauto

解决方案


If your goal is to scroll down Packet List, you can use

# workaround for set_focus() failure on uia backend
app_win32 = Application(backend="win32").connect(path=r"wireshark.exe")
app_win32.window(best_match='Qt5QWindowIcon').set_focus()
PL.wheel_mouse_input(wheel_dist=-10) # negative wheel_dist means scroll down

or try PL.type_keys('{VK_DOWN}') to scroll Packet List.

The value of IsScrollPatternAvailable property of Packet List (QTreeView widget) is false, for this reason PL.scroll("down", "line", 1) cause error message "tree "Packet list" is not scrollable". Also inspect.exe doesn't show scrollbar among PacketList's children.

Also, you can try another approach: get bottom right coordinates of the Packet List, subtract (5,5) or other delta from them and click to this point. Something like (this code just demonstrates idea, because sends click to wrong coordinates on latest Wireshark version, which may be a Qt-related problem):

arrow_coords = (PL.rectangle().right - 5, PL.rectangle().bottom - 5)
for i in range(N):
    PL.click_input(coords=arrow_coords)

推荐阅读