Choose title- and file name at runtime

£可爱£侵袭症+ 提交于 2020-01-06 15:07:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!