??????????watir 1.6x ??????????javascript??????alert??confrim????????????autoit????????????У????й????????????и???????????

??????selenium webdriver?У?confirm??alert??????????????????κε????????????

?????????html???????1?????click??button???????button?????1??alert?????

 

<html>
<head>
<title>Alert</title>
</head>
<body>
<input id = "btn" value = "click" type = "button" onclick = "alert('hello');"/>
</body>
</html>

 ????selenium webdriver????alert????????£?

 

require 'rubygems'
require 'selenium-webdriver'
dr = Selenium::WebDriver.for :firefox
frame_file = 'file:///'.concat File.expand_path(File.join(File.dirname(__FILE__)?? 'alert.html'))
dr.navigate.to frame_file
dr.find_element(:id =>'btn').click
a = dr.switch_to.alert
puts a.text #--> hello
a.accept

 

?????????????·??????id?btn?????????a = dr.switch_to.alert??????1??alert element(????????????)???????????a??????a??????alert?????puts a.text?????????alert????????????????'hello'?? a.accept?????????????????????confrim???a.accept?????????????????????????????????a.dismiss??????