$:.unshift File.join(File.dirname(__FILE__),'..','config_file')
require 'watir'
require 'url_path_config'
Watir::Browser.default ='ie'
$ie= Watir::Browser.new
$ie.maximize()
$ie.goto @path
$a =$ie.frame(:id,"mainFrame").div(:class,"areamanage_login_center_right")
$a.text_field(:name,"admin_name").set("***")
$a.text_field(:name,"admin_pwd").set("***")
$a.button(:class,"new_submit").click
#$ie.frame(:id,"leftFrame").div(:index,"4").links.each {|d| puts d}
$ie.frame(:id,"leftFrame").div(:index,"4").link(:index,1).click
$ie.frame(:id,"mainFrame").image(:index,1).click
$b =$ie.frame(:id,"mainFrame").frame(:src,"*****")
#$b.show_all_objects
#$b.div(:id,"dpTitle").text_fields.each {|d| puts d }
#$b.cells.each {|d| puts d }
#设置月份
$b.div(:id,"dpTitle").text_field(:index,"1").set("12")
#设置年份
$b.div(:id,"dpTitle").text_field(:index,"2").set("2009")
#$b.cells.each {|d| puts d }
#设置日期
$b.cell(:text,"10").click
#$b.button(:id,"dpOkInput").click
#输出当前文本输入框中的值
$ie.frame(:id,"mainFrame").text_field(:id,"startdate").attribute_value("value")
$ie.frame(:id,"mainFrame").button(:name,"Submit").click
$ie1 =Watir::IE.attach(:url,/operation=sea/)
$ie1.maximize()
#table的函数参考 lib/watir/table.rb
table =$ie1.table(:class,"table1")
#遍历table中所有的cell
#table.cells.each {|d| puts d}
#返回表的行数
row = table.row_count
#返回表的列数
column =table.column_count
a=[]
#遍历table中所有的cell
3.upto(row) do |i|
1.upto(column) do |j|
a << table.rows[i][j].to_s
end
end
#输出table中所有link
#table.links.each{|l| puts l}
#判断是否存在字段
#a.include?("合计")
#返回字段的下标
x = a.index("营口")
#返回字段所在的行数
i = x/column+1
#返回字段所在行的列数
j = x%column+1
#点击link
table.link(:text,"#{table.rows[i][j]}").click
#点击link
#table.link(:text,"沈阳").clcik
url_path_config.rb 文件
################################### 配置网址路径 ###################################
#地址:
@path = "http://**.**.**.**:**/**/**/**.jsp"
watir应用实例
最新推荐文章于 2024-02-25 22:24:49 发布