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

时间:2019-06-18 19:21:00

标签: python automation 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面板,而是问题是当我没有屏幕并尝试从上下文菜单(已创建)中进行选择时-仅文本是选择,而无需点击

1 个答案:

答案 0 :(得分:0)

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