![watir](https://img-blog.csdnimg.cn/img_convert/64b190be8026d79a6e7e3b327bcfa774.png)
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
enddef 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").clickstartClicker(“ OK”,3) $ ie.button(“提交”).click
翻译自: https://www.hanselman.com/blog/clicking-a-javascript-dialog-using-watir
watir