watir_使用Watir单击JavaScript对话框

watir

watir

There will soon be an easy way to click and generally deal with JavaScript Dialogs with Watir (Web Application Testing in Ruby, pronounced "WATER"). It's always been possible, but the team is working on ways to make it easier. Until that day comes, we use the old way. Mark Cain posted sample code recently on the Wtr-General Mailing List. I'd been meaning to post my code that fires up another Ruby "thread," but his is arguably simpler if not slightly brute force. Thanks Mark!

很快将有一种简单的方法可以单击并使用Watir处理JavaScript对话框(Ruby中的Web应用程序测试,发音为“ WATER”)。 总是有可能的,但是团队正在研究使其更容易的方法。 在这一天到来之前,我们使用旧的方式。 Mark Cain最近在Wtr-General Mailing List上发布了示例代码。 我本来打算发布我的代码来启动另一个Ruby“线程”,但是可以说,如果不是蛮力的话,他的代码会更简单。 谢谢马克!

#Put this method in your script:

#将此方法放入脚本中:

def startClicker( button , waitTime = 3)
   w = WinClicker.new
   longName = $ie.dir.gsub("/" , "\\" )
   shortName = w.getShortFileName(longName)
   c = "start ruby #{shortName}\\watir\\clickJSDialog.rb #{button}
#{waitTime} "
   puts "Starting #{c}"
   w.winsystem(c)
   w=nil
 end

def startClicker(button,waitTime = 3) w = WinClicker.new longName = $ ie.dir.gsub(“ /”,“ \\”) shortName = w.getShortFileName(longName) c =“启动ruby#{shortName} \\ watir \\ clickJSDialog.rb#{button} #{waitTime}” 放置“开始#{c}” w.winsystem(c) w =无结束

#Then call it right before you click the button (or whatever) that
causes the javascript popup to display:

然后在点击按钮(或其他按钮)之前将其调用使javascript弹出窗口显示:

startClicker("OK" , 3)
$ie.button("Submit").click

startClicker(“ OK”,3) $ ie.button(“提交”).click

翻译自: https://www.hanselman.com/blog/clicking-a-javascript-dialog-using-watir

watir

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值