def wait_for_element_present(element)
wait = Selenium::WebDriver::Wait.new(:timeout => 30);
wait.until{driver.find_element(element)};
end
Please take a look at the Ruby code above, I have two questions:
(1) As for “Selenium::WebDriver::Wait.new(:timeout => 30)”, what does the “=>” mean here? I know “:timeout” is a ruby symbol, but when using it following by a “=>” and a value “30”, I get confused. Is this some kind of trick about ruby symbol?
(2) We also have the symbol “=>” when defining hash right? Like:
cars = {
'altima' => 'nissan',
'camry' => 'toyota',
'rx7' => 'mazda'
}
puts cars['rx7'] => mazda
Does the “=>” here has the same meaning as that in question (1)?
I’m a ruby newbie, any comments would be appreciated. Thanks in advance!
Yes, it has the same meaning. In both cases, it’s definition of a hash. Ruby allows to omit curly braces of hash literal, if it is the last parameter in method’s signature.
Example:
Note that it only works for last parameter which is hash. If you have several hashes at the end, you have to use normal form (with curly braces) for all but the last.