文本框:
<INPUT id="email" name="_fmu.u._0.e" value="" />
方法1: ie.text_field(:id,'email').set("文本内容")
方法2: ie.text_field(:name, 'email').set("文本内容")
方法3: ie.text_field(:name,"email").clear
下拉框:
<SELECT name="cert_no">
<OPTION value="身份证">身份证</OPTION>
</SELECT>
方法1: ie.select_list(:name,"cert_no").select("身份证")
方法2: ie.select_list(:name,"cert_no").clearSelection
超链接:
<a href = "http://www.google.cn/">google</a>
方法1:ie.link(:text,"google").click
方法2:ie.link(:url,"http://www.google.cn/").click
复选框:
<input type = "checkbox" name = "checkme" value = "1">
方法1: ie.checkbox(:name,"checkme").set
方法2: ie.checkbox(:name,"checkme").clear
方法3: values = ie.checkbox(:name,"checkme").value
<input type = "checkbox" name = "checkme" value = "2">
#多个同名的复选框处理
方法1: ie.checkbox(:name,"checkme","2").set
方法2: ie.checkbox(:name,"checkme","2").clear
单选框:
<input type = "radio" name = "clickme" id = "1">
方法1: ie.radio(:name, "clickme").set
方法2: ie.radio(:name, "clickme").clear
一般按钮:
<input type = "button" name = "clickme" value = "Click Me">
方法1: ie.button(:value, "Click Me").click
方法2: ie.button(:name,"clickme").click
submit按钮:
<form action = "submit" name = "submitform" method = "post">
<input type = "submit" value = "Submit"></input>
</form>
方法: ie.button(:value."Submit").click
图片按钮:
<form action ="submit" name = "doitform" method = "post">
<input type = "image" src = "images/doit.gif" name = "doit">
</form>
方法:ie.button(:name, "doit").click
Form中无按钮:
<form action = "login" name = "loginform" method = "get">
<input name = "username" type = "text"></input>
</form>
方法1:ie.form(:name,"loginform").submit
方法2:ie.form(:action,"login").submit
获取隐含对象值:
<INPUT type=hidden value="您的Email" name="field1">
方法:values = ie.hidden(:name,'field1').value
获取窗口对象:
方法1: ie2 = Watir::IE.attach(:url,'http://www.google.cn/') #根据URL获取
方法2: ie3 = Watir::IE.attach(:title,'Google') #根据窗口标题获取
方法3: ie4 = Watir::IE.attach(:title, /google.cn/) #正则表达式匹配获取
URL编码:
require 'cgi'
string = "URL编码"
string = CGI::escape(string)
puts string # 转换结果: URL%B1%E0%C2%EB
URL解码:
require 'cgi'
string = "URL%BD%E2%C2%EB"
string = CGI::unescape(string)
puts string # 转换结果:URL解码