我是Watir世界的新人。我认为我的问题很容易,但我无法完成。
这是我的代码:
names = Hash.new
names[:text] = 'Image'
puts names
browser.a("#{names}").click
我收到此错误:
'extract_selector': expected Hash or (:how, 'what'), got ["{:text=>\"Image\"}"] (ArgumentError)
print
显示正确的值为"{:text=>"Image"}"
。
答案 0 :(得分:2)
如果你仔细阅读错误信息 - *'extract_selector':预期的哈希或(:怎么样,'什么')*
试试这个:
browser.a(:text => 'Image').click
:how :what
然后(根据OP的评论)
browser.a(names).click
Hash
以下是完整代码:
require 'watir-webdriver'
b = Watir::Browser.new
b.goto "http://en.wikipedia.org/wiki/Ruby_(programming_language)"
# <a href="/wiki/Just-in-time_compilation" title="Just-in-time compilation">just-in-time compilation</a>
hsh = {:text => 'just-in-time compilation'}
b.a(hsh).text # => "just-in-time compilation"
答案 1 :(得分:0)
它说它期望一个哈希,所以不要给它一个字符串:
browser.a(names).click