利用pywinau实现自动控制

2024-09-28 03:24:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pywinauto-lib尝试一个utorrent自动化。我想添加一个带有网址的torrent。此选项位于“文件”菜单下。我可以开到最远的地方,然后什么都没有发生。我用Swapy来生成这段代码。下面的框只有在我用swapy运行代码时才会打开。但是当我把它保存到一个文件中并用cmd运行时,只有utorrent打开,并且在cmd中进行回溯。在

The Box where I want to enter the URL and Click OK

from pywinauto.application import Application

app = Application().Start(cmd_line=u'"C:\\Users\\User\\AppData\\Roaming\\uTorrent\\u Torrent.exe" ')
torrentdfb = app[u'\xb5Torrent4823DF041B09']
torrentdfb.Wait('ready')
menu_item = torrentdfb.MenuItem(u'&File->Add Torrent from &URL...\tCtrl+U')
menu_item.Click()

app.Kill_()

Traceback:
Traceback (most recent call last):
File "AddTorrent.py", line 5, in <module>
torrentdfb.Wait('ready')
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 380, in Wait
WaitUntil(timeout, retry_interval, lambda: self.__check_all_conditions(check_method_names))
File "C:\Python27\lib\site-packages\pywinauto\timings.py", line 308, in WaitUntil
raise err
pywinauto.timings.TimeoutError: timed out

我是python编码新手,不是专家。如果你能解释我的问题或代码,那会很有帮助。谢谢!!在


Tags: 文件代码infrompycmdappapplication
1条回答
网友
1楼 · 发布于 2024-09-28 03:24:03

uTorrent正在生成另一个进程,我是这样得到它的:

>>> app.windows_()
[]
>>> app.process
6096
>>> app.connect(title_re=u'^μTorrent.*(build \d+).*')
<pywinauto.application.Application object at 0x000000000405C240>
>>> app.process
4044L

这是最后一个适合我的代码(使用32位uTorrent和32位python2.7):

^{pr2}$

咬紧牙关很重要。如果我使用64位Python,32位uTorrent崩溃。在

相关问题 更多 >

    热门问题