首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有办法找到任何windows应用程序的启动时间?

有没有办法找到任何windows应用程序的启动时间?
EN

Stack Overflow用户
提问于 2020-09-02 01:01:07
回答 1查看 18关注 0票数 0

假设我正在使用VLC Player,并且我想要计算使用python启动所需的时间,有什么方法吗?

我已经尝试过winium自动化,但元素加载太慢。我想要获得我的应用程序的启动时间,它在4-5秒内启动,而winium通常需要更多的时间来找到元素的位置。

如果任何人可以建议任何更好的方法通过后端自动化,请评论。

EN

回答 1

Stack Overflow用户

发布于 2020-09-02 01:59:53

如果我没理解错的话,你需要找出从你执行应用程序到窗口出现的时间。你可以使用pygetwindow库来做到这一点。代码如下:

代码语言:javascript
运行
复制
    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)

编辑

您还可以通过检查窗口数量是否发生变化来检测应用程序的启动。

代码语言:javascript
运行
复制
    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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63692269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档