python - 没有用户会话时,Pywinauto 自动化失败
问题描述
我正在研究程序自动化(名为 SEO indexer 的程序)。我使用 python 的库名称 pywinauto 编写了自动化。当我通过与服务器的 RDP 连接运行自动化时,一切都很好。但是,当我试图离开程序并与 RDP 断开连接时,“另存为”窗口窗口没有启动并且程序崩溃......
有人知道我该如何解决?
负责保存文件的代码是 -
def run(self, process_id, link):
controls = self._app[u'TForm1']
text_box = controls.Edit
text_box.set_text(link)
button = controls.ToolBar1
windows = Desktop(backend="uia")
button.click()
self.wait_for_finish(process_id)
result_box = controls.TVirtualStringTree
result_box.RightClick()
sleep(1)
windows_list = windows.windows()
context_menu = windows.window(best_match = "Context")
save_all_button = context_menu.children()[2]
save_all_button.select()
save_as = windows.window(best_match = "save_as")
properties_section = save_as.children()[0]
file_name = "C:\\Windows\\Temp\\indexer_" + str(randint(0, 10000))
file_name_label = properties_section.children()[4].children()[0]
file_name_label.set_text(file_name)
save_button = save_as.children()[2]
save_button.click()
sleep(2)
yes_no_dialog = windows.window(best_match = "GSA SEO Indexer v2.34")
yes_no_dialog.children()[0].click()
return file_name
它坠毁在 -
save_as = windows.window(best_match = "save_as")
即使没有屏幕,有没有办法强制它打开另存为对话框?
更新:
我只是注意到问题不在于Save as
未创建面板,问题在于当我没有屏幕并尝试从上下文菜单(已创建)中进行选择时-仅选择了文本,而不单击它
解决方案
远程执行指南是您所需要的。这是任何 GUI 自动化工具的常见问题。所以这个问题并不完全与 pywinauto 相关,但我在一年前写了这个指南来为许多用户解决这个问题。
推荐阅读
- javascript - How can I set value to componentDidMount from another function in React?
- c - 从 C 中获取 *ABS* 符号的值
- codenameone - 代号一透支
- c# - C# - 当使用out关键字传递引用类型时,调用函数代码可以控制外部对象吗?
- java - Spring 云服务器未从 Vault 后端访问所有配置文件
- python - 错误:TypeError:__init__() 接受 1 个位置参数,但给出了 2 个
- python - 如何在 python 中使用“with”从 mysql.connector.pooling 打开连接?
- asp.net-core - __EFMigrationsHistory 表仍然为空,尽管应用了 update-database 命令
- xamarin.forms - 如何在 xamarin Android 中使用 netstandard 2.1?
- javascript - RequireJS - 看不到页面内部的变量