在运行时选择标题和文件名 [英] Choose title- and file name at runtime

查看:81
本文介绍了在运行时选择标题和文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个浏览器中自动执行文件上传,但是窗口名称在Firefox中为"File Upload",在Chrome中为"Open".我不想编写两个不同的脚本.

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.

如何在运行时选择标题和文件名以实现跨浏览器兼容性?我使用Selenium和testNG,AutoIt仅用于文件上传.

How to choose title- and file name at runtime to achieve cross browser compatibility? I use Selenium and testNG, AutoIt only for file upload.

推荐答案

根据使用的Web浏览器设置一个变量,然后使用该变量.下面的代码将使您走上正确的轨道.

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

这篇关于在运行时选择标题和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆