首页 > 解决方案 > 没有用户会话时,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未创建面板,问题在于当我没有屏幕并尝试从上下文菜单(已创建)中进行选择时-仅选择了文本,而不单击它

标签: pythonautomationpywinauto

解决方案


远程执行指南是您所需要的。这是任何 GUI 自动化工具的常见问题。所以这个问题并不完全与 pywinauto 相关,但我在一年前写了这个指南来为许多用户解决这个问题。


推荐阅读