假设我正在使用VLC Player,并且我想要计算使用python启动所需的时间,有什么方法吗?
我已经尝试过winium自动化,但元素加载太慢。我想要获得我的应用程序的启动时间,它在4-5秒内启动,而winium通常需要更多的时间来找到元素的位置。
如果任何人可以建议任何更好的方法通过后端自动化,请评论。
发布于 2020-09-02 01:59:53
如果我没理解错的话,你需要找出从你执行应用程序到窗口出现的时间。你可以使用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 Player
https://stackoverflow.com/questions/63692269
复制相似问题