没有用户会话时 Pywinauto 自动化失败

Pywinauto automation fails when there is no user session

我正在研究程序自动化(名为 SEO 索引器的程序)。我使用 python 的库名称 pywinauto 编写了自动化程序。 当我 运行 通过 RDP 连接到服务器的自动化时,一切都很好。但是当我试图离开程序并断开与 RDP 的连接时,"Save AS" windows window 没有启动并且程序崩溃了......

有人知道我该如何解决吗?

负责保存文件的代码是 -

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 面板,问题是当我没有屏幕并尝试从上下文菜单(已创建)中 select ) - 只是 select 编辑了文本,没有点击它

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