【发布时间】:2020-12-20 20:09:40
【问题描述】:
假设我正在使用 VLC Player,我想计算使用 python 启动所需的时间,有什么办法吗?
我尝试过 winium 自动化,但元素加载速度太慢。我想获得我的应用程序的启动时间,它会在 4-5 秒内启动,而 winium 通常需要更多时间才能找到元素的位置。
如果有人可以通过后端自动化提出更好的方法,请发表评论。
【问题讨论】:
标签: python windows automation operating-system
假设我正在使用 VLC Player,我想计算使用 python 启动所需的时间,有什么办法吗?
我尝试过 winium 自动化,但元素加载速度太慢。我想获得我的应用程序的启动时间,它会在 4-5 秒内启动,而 winium 通常需要更多时间才能找到元素的位置。
如果有人可以通过后端自动化提出更好的方法,请发表评论。
【问题讨论】:
标签: python windows automation operating-system
如果我理解正确,您需要找出从执行应用程序到出现窗口的时间。您可以使用 pygetwindow 库来做到这一点。代码如下:
import pygetwindow as pw
import time
# here's code that executing the program, but i just put comment
start = time.time()
while 1: # waiting until window appears
# getWindowsWithTitle method returns empty list if it didn't found any windows with this name
if pw.getWindowsWithTitle('VLC'): #if it founds the window, loop will break
break
stop = time.time()
result = stop - start # result is time in seconds (type float)
编辑
您还可以通过检查窗口数量是否更改来检测应用程序的启动。
import pygetwindow as pw
import time
starting_amount = len(pw.getAllWindows()) # amount of windows
# here's code that executing the program, but i just put comment
start = time.time()
while 1: # waiting until window appears
if len(pw.getAllWindows()) > starting_amount: #if amount of windows is bigger than it was before we executed the program
break
stop = time.time()
result = stop - start # result is time in seconds (type float)
这应该适用于 LD 播放器
【讨论】: