options = {
:type => 'textarea',
:selector => :id,
:field => 'id_of_textarea_field',
:value => 'Joe Salesperson'
}
您只需傳遞標識符,不需要引號。
2017-01-03,使用用例進行更新。這是我正在使用的方法和調用的聲明。實際的代碼比我在這裏粘貼的代碼更詳細,包含不同的驗證。在這個例子中,您會注意到一個簡單的開關塊,它根據傳遞的元素類型(特別是文本區域,文本字段和選擇元素)設置適當的信息。
def validateInput(options = {})
success = true
begin
case options[:type]
when 'textarea', 'text_field'
Watir::Wait.until{$browser.textarea(options[:selector] => options[:field]).present?}
$browser.textarea(options[:selector] => options[:field]).set options[:value]
when 'select'
$browser.select_list(options[:selector] => options[:field]).select_value options[:value]
else
puts "in else"
end
end
rescue => e
$message.push("Failed to validate '#{options[:field]}' field. #{e}")
success = false
end
return success
end
validateInput({
:type => 'textarea',
:selector => :id,
:field => 'order_approval_comment_name',
:value => 'Joe Salesperson'
})
我想知道通過這種方式的用途是什麼? – Gopal
@Gopal,我已經更新了我的答案。希望這爲你提供更好的清晰度。 –
好的,謝謝。 – Gopal