如何解决有没有办法找到任何Windows应用程序的启动时间?
假设我正在使用VLC Player,并且我想计算使用python启动所需的时间,有什么办法吗?
我尝试过winium自动化,但是元素加载太慢。我想获得应用程序的启动时间,并在4-5秒内启动,而winium通常花费更多的时间来查找元素的位置。
解决方法
如果我理解正确,那么您需要查找从执行该应用程序到窗口出现之间的时间。您可以使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。