无法使用标题的 Class 使用 AutoIt 自动上传 Windows 文件

Can't use a title's Class to automate Windows file upload using AutoIt

我正在尝试使用 AutoIt Windows 文件上传。我正在单击将打开文件上传弹出窗口的浏览按钮。我希望 AutoIt 键入文件的位置并单击打开。

我需要使用FF、Chrome、IE进行测试。如果我使用标题,我可以让它工作,但问题是每个浏览器都有不同的标题。我想使用 class,因为它适用于所有浏览器的 #32700。我试过使用 class 而不是标题,但它不起作用。

当我使用 title 时,一切正常。以下是 Firefox 的示例。在此脚本中,输入文件名并单击打开。

ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload", "", "Edit1", "SomeFile.txt")
ControlClick("File Upload", "","Button1");

当我尝试使用 class 时,没有输入文本,也没有点击打开按钮。 AutoIt 脚本编辑器中没有错误,所以我不确定为什么这不起作用。

ControlFocus("[CLASS:#32770]","","Edit1")
ControlSetText("[CLASS:#32770]", "", "Edit1", "SomeFile.txt")
ControlClick("[CLASS:#32770]", "","Button1");

我还尝试将所有三个浏览器标题添加到 1 个 AutoIt 脚本中。以下脚本适用于 Firefox 和 IE,但在 Chrome 中不执行任何操作。

Local $OrgFile = "SomeFile.csv"
Local $ControlIDText = "Edit1"
Local $ControlIDButton = "Button1"
Local $Title_FF = "File Upload"
Local $Title_Chrome = "Open"
Local $Title_IE = "Choose File to Upload"

;Firefox Import
ControlFocus($Title_FF,"",$ControlIDText)
ControlSetText($Title_FF, "", $ControlIDText, $OrgFile)
ControlClick($Title_FF, "",$ControlIDButton);

;Chrome Import
ControlFocus($Title_Chrome,"",$ControlIDText)
ControlSetText($Title_Chrome, "", $ControlIDText, $OrgFile)
ControlClick($Title_Chrome, "",$ControlIDButton);

;IE Import
ControlFocus($Title_IE,"",$ControlIDText)
ControlSetText($Title_IE, "", $ControlIDText, $OrgFile)
ControlClick($Title_IE, "",$ControlIDButton);

如果您想使用高级标题匹配(例如CLASS),您需要将 WinTitleMatchMode 选项设置为 4。

#RequireAdmin ;Will give your script a permission elevation (sometimes its needed)
Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ;0=no, 1=search children also

ControlFocus("[CLASS:#32770]","","Edit1")
ControlSetText("[CLASS:#32770]", "", "Edit1", "SomeFile.txt")
ControlClick("[CLASS:#32770]", "","Button1");