以下代码支持Firefox,IE,Chrome
require 'watir-webdriver'
#require "watir-webdriver/extensions/alerts"
b = Watir::Browser.new :chrome
b.goto("http://192.168.10.110:ab/PersonInfo.aspx")
b.text_field(:id, "txtName").set("w3")
b.text_field(:id, "txtPwd").set("w3")
b.button(:id, "Logininfo").click
b.form(:id, "Form1").button(:name, "ctl00$MainContent$ctl00").click
b.link(:id, "MainContent_gridview_LinkButton1_0").click
if b.alert.present?
puts b.alert.text
b.alert.ok
end
browser.alert.ok # Will click OK button on the popup
browser.alert.close #Will click Cancel button/close on the popup
browser.alert.text #Will return the text on the popup