|
刚从网上搜到的使watir支持中文输入的方法,碰到过相同问题的同学可以直接改了。。
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")
} |
|