通过Watir-Webdriver中的内容查找textarea

时间:2012-08-31 17:00:35

标签: watir-webdriver

我无法断言存在某些内容的textarea。 这是我希望做的一个例子:

require 'watir-webdriver'

b = Watir::Browser.new :ff

b.goto 'http://www.velnetsupport.co.uk/parrots/FormMail/example_form.html'

b.text_field(:name => 'realname').set 'Tom Jones'
puts b.text_field(:value => /om\ Jon/x).exists? # Expect true get true

b.text_field(:name => 'message').set 'John Jones'
puts b.text_field(:value => /ohn Jon/).exists? # Expect true get false

b.close

这应该有用吗?还有另一种方式吗?

提前致谢

2 个答案:

答案 0 :(得分:2)

您在上面犯了一个错误,用textarea替换文本字段

puts b.textarea(:value => /ohn Jon/).exists?

答案 1 :(得分:0)

您可以考虑这样做,而不是:

b.text_field(:name => 'message').set 'John Jones'

# The next line assumes you're using Rspec...
b.text_field(:name => 'message').text.should=='John Jones'

# Alternatively, if you're using TestUnit...
assert_equal(b.text_field(:name => 'message').text, 'John Jones')

# Or, do your own verification:
puts "Exists!" if b.text_field(:name => 'message').text=='John Jones'