watir安装备忘(Rubygem)

来源:互联网 发布:mac 查看系统版本 编辑:程序博客网 时间:2024/04/30 22:01

A
使用Watire可以获得页面上的各种元素,比如button,link...,然后你可以对这些元素进行操作
与网页交互(Interacting With a Web Page)

B
需要Ruby1.8.5

C
支持中文的话
要watir1.5.2

步骤如下:
1.打开watir.rb
2.在class TextField中加入一个新的method:
    def characters_in(value)
        index = 0
        while index < value.length
         len = value[index] > 128 ? 2 : 1
         yield value[index, len]
         index += len
        end
    end

3.更改class TextField的doKeyPress( value )方法部分代码,将下面代码
-------------------------------------------
    for i in 0 .. value.length-1
        sleep @container.typingspeed
        c = value[i,1]
        @container.log " adding c.chr " + c  
        @o.value = @o.value.to_s + c   
        @o.fireEvent("onKeyDown")
        @o.fireEvent("onKeyPress")
        @o.fireEvent("onKeyUp")
      end

替换为如下代码
      characters_in(value) {|c|
        sleep @container.typingspeed
        @o.value = @o.value.to_s + c
        @o.fireEvent("onKeyDown")
        @o.fireEvent("onKeyPress")
        @o.fireEvent("onKeyUp")
       }