问题描述
#!/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)
解决方法
如果您的目标是向下滚动“数据包列表”,则可以使用
glob
或尝试# 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
滚动“数据包列表”。
数据包列表(QTreeView窗口小部件)的PL.type_keys('{VK_DOWN}')
属性的值为IsScrollPatternAvailable
,因此false
导致错误消息“树“数据包列表”不可滚动”。而且inspect.exe不在PacketList的子级之间显示滚动条。
此外,您可以尝试另一种方法:获取“数据包列表”的右下角坐标,从中减去(5,5)或其他增量,然后单击此处。之类的东西(此代码仅演示思想,因为将点击发送到最新Wireshark版本上的错误坐标,这可能是Qt相关的问题):
PL.scroll("down","line",1)