Here’s a snippet for establishing and accessing a hash in Ruby. I used Watir for this:
colorHash = { ‘None’ => 0, ‘Bright White’ => 1, ‘Jet Black’ =>2, ‘Castlerock’=>3, ‘Navy’=>4, ‘Khaki’=>5, ‘Sport Red’=>6, ‘Espresso’=>7, ‘Blue Radiance’=>8, ‘Sun Orange’=>9, ‘Medium Green’=>10 }
To access an item in the hash:
$ie.link(:id,”productAttributes#{$colorHash[$colorChosen]}”).click
To loop through each element in the hash, use a hash.each do loop.
Note: This will not iterate the hash in the order the elements are defined. Hashes are not in order like arrays are.
colorHash.each do |key, value|
$ie.link(:id,”productAttributes#{colorHash[key]}”).click
$ie.wait()

You must log in to post a comment.