我正在使用autoit在Web应用程序中上传文件。我正计划整合https://www.guru99.com/use-autoit-selenium.html
中提到的Selenium和AutoIt我现在的问题是当我单击上载按钮时,在chrome上载窗口标题为“打开”,而在Firefox中标题为“文件上载”。所以我的问题是有什么办法可以自动使用不同的值来查找窗口标题。即“打开”或“文件上传”
这是我用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")
答案 0 :(得分:0)
您可以使用正则表达式来查找所需的窗口:
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")
但是,这仍然不是一种非常可靠的方法。另外还可以考虑其他一些建议:
#32770
WinGetHandle("[ACTIVE]")