【问题标题】:pywinauto access a nested submenuepywinauto 访问嵌套的子菜单
【发布时间】:2021-11-11 13:27:58
【问题描述】:

在 pywinauto 中,我试图访问包含的嵌套子菜单项。 路径是 Datei->Importieren->Vorlagen->comdirect Musterdepot(附截图)

知道我怎样才能让它运行吗?

我使用的代码:

app = Application(backend = 'uia').connect(path = "PortfolioPerformance.exe")
app.Dialog.Anwendungsmenü.item_by_path('Datei->Importieren->Vorlagen->comdirect Musterdepot').click_input()

我收到的错误:

AttributeError: 'NoneType' object has no attribute 'is_active'

菜单截图:

【问题讨论】:

  • 请检查'Vorlagen->->comdirect Musterdepot' 中的双箭头(->->)是否可能导致问题。
  • 谢谢,复制代码时不小心出现了双箭头。它不会导致问题。
  • 阅读以前关于类似问题的答案,请尝试查看更改为菜单编号是否有帮助。即,代替Datei->Importieren->Vorlagen->comdirect Musterdepot' 使用#0->#8->#2->#0。有关更多详细信息,请参阅此答案 - stackoverflow.com/a/33301892/12950723
  • 我也尝试过使用 hash variables ,即 #0->#8->#2->#0 确实具有相同的结果。问题是脚本总是在菜单的第三级引发 AttributeError。即 Datei->Speichern 工作,Datei->Importieren 工作,Datei->Importieren->comdirect Musterdepot 失败,Datei->Speichern unter->XML 失败。

标签: python pywinauto


【解决方案1】:

花了一些时间后,我发现了以下行为: 一旦我展开 Datei 菜单,print_control_identifiers 就会更新以包含子菜单。 以下代码会点击正确,但也许有更好的解决方案:

app = Application(backend = 'uia').connect(path = PROCNAME)
dialog = app.dialog
#first open the Importieren submenu:
dialog.Anwendungsmenü.item_by_path('Datei->Importieren') 
# then the submenue appears on top level menues, open the importieren menu:
dialog["Importieren"].item_by_path('Vorlagen->comdirect Musterdepot').select()

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2023-04-07
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多