使用 OR 条件识别具有两个 class 名称的 window 标题

Identify window title with two class names using OR condition

我正在使用 autoit 在我的网络应用程序中上传文件。我正计划集成 Selenium 和 AutoIt,如 https://www.guru99.com/use-autoit-selenium.html

中所述

我现在的问题是当我点击上传按钮时 在 chrome 中上传 window 标题为 "Open" 而在 Firefox 中标题为 "File Upload"。所以我的问题是 autoit 中是否有任何方法可以使用不同的值查找 window 标题。即 "Open" 或 "File Upload"

这是我在 chrome

中上传文件的代码
WinWait("Open", "", 60)
WinActivate("Open")
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1", "C:\abc.war")
ControlClick("Open","", "Button1")

这是我在 firefox 中上传文件的代码

WinWait("File Upload", "", 60)
WinActivate("File Upload")
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1", "C:\abc.war")
ControlClick("File Upload","", "Button1")

您可以使用正则表达式来找到所需的 window:

Opt("WinTitleMatchMode", 4)

$handle = WinGetHandle("[REGEXPTITLE:(?:Open|File Upload)]")

;In case window was not found
If @error Then Exit

WinWait($handle, "", 60)
WinActivate($handle)
ControlFocus($handle,"","Edit1")
ControlSetText($handle,"","Edit1", "C:\abc.war")
ControlClick($handle,"", "Button1")

然而,这仍然不是一个非常稳健的方式。另外可以考虑的一些其他建议:

  • 检查 window class。上传window是一个对话框,所以根据this list
  • 它的class会是#32770
  • 使用WinGetHandle("[ACTIVE]")
  • 检查当前活动的window