Reputation: 127
contents = $ie.select_list(:id, "dropdown").getAllContents
puts contents.currentstyle.color
It showing error as
1) Error:
test_01(TC_Login):
NoMethodError: undefined method `currentstyle' for
Can any one help as i need to fetch particular record with particular color
Upvotes: 1
Views: 705
Reputation: 46846
Assuming you have HTML like this:
<select name="list" id="select_list">
<option value="1" style="color:blue" SELECTED>Name1</option>
<option value="2" style="color:green">Name2</option>
<option value="3" style="color:green">Name3</option>
</select>
The only way I have found to get the colour of an option was to access it directly (from the win32ole object). The following would output the colour of the first option.
puts $ie.select_list(:id, "dropdown").document.options(0).style.color
If you want to get the Watir::Option object that has the matching colour, you can do:
matching_colour = 'green' # Colour you want
# Iterate through the options to find the first match
select_list_element = ie.select_list(:id, 'dropdown')
matching_option = nil
select_list_element.document.options.each{ |o|
if o.style.color == matching_colour
matching_option = select_list_element.option(:text, o.text)
break
end
}
# Do something with the option if one was found
if match_option.nil?
#Nothing matches
else
#Do something with the option, like select it
matching_option.select
end
Upvotes: 1