有没有办法让pywinauto
找到一个只包含部分标题的窗口?
这是我的代码:
import pywinauto
pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Minitab Professional 5.1 64bit - 3333348.temp.project',
class_name='Window')[0]
问题是每次打开软件时,temp.project
之前的数字都会改变,因此我无法让pywinauto
找到正确的窗口。
title_re
作为Python正则表达式工作。在你的情况下应该是title_re=u'Minitab Professional 5\.1 64bit - \d+\.temp\.project'
。\.
表示点符号,.
表示任何符号。对于全功能对话框包装器(而不是句柄),下面的事情更简单:
它用适当的
process
参数(这是pid)调用find_window
,因此您不会被来自多个应用程序实例的许多类似窗口所混淆。顺便说一下,对于64位应用程序,您需要64位兼容的pywinauto克隆(官方的0.4.2只支持32位Python和应用程序,因为不同的WinAPI结构对齐方式)。
在这种情况下,最好通过路径连接到应用程序,例如:
通过浏览google code上的源代码,我发现您可以为标题提供regex:
据我所知,
pywinauto.findwindows.find_windows(title_re = r'Minitab Professional 5.1 64bit*', class_name='Window')[0]
应该有用。相关问题 更多 >
编程相关推荐