问题
I am trying to automate file upload in two browsers but the window name is "File Upload" in Firefox and "Open" in Chrome. I don't want to write two different scripts.
How to choose title- and file name at runtime to achieve cross browser compatibility? I use Selenium and testNG, AutoIt only for file upload.
回答1:
Set a variable based off the web browser being used, then use that variable. The code below should get you on the right track.
$FirefoxUpload = "File upload"
$ChromeUpload = "Open"
if WinExists($FirefoxUpload)
$UploadWindow = $FirefoxUpload
elseif WinExists($ChromeUpload)
$UploadWindow = $ChromeUpload
else
$UploadWindow = ""
endif
if $UploadWindow <> ""
ControlFocus($UploadWindow,"","Edit1")
ControlsetText($UploadWindow,"","Edit1","C://file.xls")
ControlClick($UploadWindow,"","Button1")
endif
来源:https://stackoverflow.com/questions/37234455/choose-title-and-file-name-at-runtime