Interesting I was thrown off when it looked like some object instead of a simple array. In the documentation<http://wiki.openqa.org/display/WTR/Selection+Boxes#SelectionBoxes-SelectionBoxMethods>it stated " NOTE: contents will be an array " which made me confused thanks for the clarification on it.
krizzo On Tuesday, April 24, 2012 2:29:57 PM UTC-6, Chuck van der Linden wrote: > > select_list.options returns an object of type OptionCollection not an > array > > It supports most of the methods you'd expect for an array in terms of > simple navigation (.each, .first, [], .length, etc) so you can pretty > much treat it as an array, but you can't (I'm pretty sure) assign it to an > array without first converting it into an array. > > See here for more info on that object type. > http://rubydoc.info/github/watir/watir-webdriver/Watir/OptionCollection > > Most of the methods such as [] or .each would return an option object, the > methods for which you can see here > http://rubydoc.info/github/watir/watir-webdriver/Watir/Option > > I'm pretty sure you'd want to call the .to_a method on the > objectcollection to get an array. I'm not sure exactly what will be in the > resulting array when it turns the collection into an array, it might be a > set of hashes or something given that each option object has at least two > properties if not three (value, text, selected?) > > Or just trying assigning it to a variable, and see if that works > > to see the details on each option in the list, try something along these > lines > > b.select_list(:name => 'entry.6.single').options.each do |option| > puts "the option is listed as: #{option.text} and selected? returns: > #{option.selected?}" > end > > > > > On Tuesday, April 24, 2012 12:30:04 PM UTC-7, krizzo wrote: >> >> I created this test script because I was having issues with another >> script that needed to work with select_list. This is having the same issue. >> From my understanding "contents[0]" should print out "Firefox" but instead >> I get a memory location. I printed the "memory" location out and it's not a >> simple array of the options it almost looks like the browser object. >> >> I wanted to know if this was a known issue or is my understanding >> incorrect on options returning an array? >> >> ## Output >> #<Watir::Option:0x816f138> >> [ >> [0] "test", >> [1] "one", >> [2] "two", >> [3] "three" >> ] >> >> ## Test Script >> >> require 'rubygems' >> require 'ap' >> require 'watir-webdriver' >> url = " >> https://spreadsheets.google.com/viewform?hl=en&formkey=dDliTk5XU1R4RUMtb2c1WDZxWHNENmc6MQ#gid=0 >> " >> myArray = %w[test one two three] >> b = Watir::Browser.new :firefox, :profile => 'LoL' >> b.goto url >> contents = Array.new >> contents = b.select_list(:name => 'entry.6.single').options >> puts contents[0] >> ap myArray >> b.close >> >> > On Tuesday, April 24, 2012 12:30:04 PM UTC-7, krizzo wrote: >> >> I created this test script because I was having issues with another >> script that needed to work with select_list. This is having the same issue. >> From my understanding "contents[0]" should print out "Firefox" but instead >> I get a memory location. I printed the "memory" location out and it's not a >> simple array of the options it almost looks like the browser object. >> >> I wanted to know if this was a known issue or is my understanding >> incorrect on options returning an array? >> >> ## Output >> #<Watir::Option:0x816f138> >> [ >> [0] "test", >> [1] "one", >> [2] "two", >> [3] "three" >> ] >> >> ## Test Script >> >> require 'rubygems' >> require 'ap' >> require 'watir-webdriver' >> url = " >> https://spreadsheets.google.com/viewform?hl=en&formkey=dDliTk5XU1R4RUMtb2c1WDZxWHNENmc6MQ#gid=0 >> " >> myArray = %w[test one two three] >> b = Watir::Browser.new :firefox, :profile => 'LoL' >> b.goto url >> contents = Array.new >> contents = b.select_list(:name => 'entry.6.single').options >> puts contents[0] >> ap myArray >> b.close >> >> On Tuesday, April 24, 2012 2:29:57 PM UTC-6, Chuck van der Linden wrote: > > select_list.options returns an object of type OptionCollection not an > array > > It supports most of the methods you'd expect for an array in terms of > simple navigation (.each, .first, [], .length, etc) so you can pretty > much treat it as an array, but you can't (I'm pretty sure) assign it to an > array without first converting it into an array. > > See here for more info on that object type. > http://rubydoc.info/github/watir/watir-webdriver/Watir/OptionCollection > > Most of the methods such as [] or .each would return an option object, the > methods for which you can see here > http://rubydoc.info/github/watir/watir-webdriver/Watir/Option > > I'm pretty sure you'd want to call the .to_a method on the > objectcollection to get an array. I'm not sure exactly what will be in the > resulting array when it turns the collection into an array, it might be a > set of hashes or something given that each option object has at least two > properties if not three (value, text, selected?) > > Or just trying assigning it to a variable, and see if that works > > to see the details on each option in the list, try something along these > lines > > b.select_list(:name => 'entry.6.single').options.each do |option| > puts "the option is listed as: #{option.text} and selected? returns: > #{option.selected?}" > end > > > > > On Tuesday, April 24, 2012 12:30:04 PM UTC-7, krizzo wrote: >> >> I created this test script because I was having issues with another >> script that needed to work with select_list. This is having the same issue. >> From my understanding "contents[0]" should print out "Firefox" but instead >> I get a memory location. I printed the "memory" location out and it's not a >> simple array of the options it almost looks like the browser object. >> >> I wanted to know if this was a known issue or is my understanding >> incorrect on options returning an array? >> >> ## Output >> #<Watir::Option:0x816f138> >> [ >> [0] "test", >> [1] "one", >> [2] "two", >> [3] "three" >> ] >> >> ## Test Script >> >> require 'rubygems' >> require 'ap' >> require 'watir-webdriver' >> url = " >> https://spreadsheets.google.com/viewform?hl=en&formkey=dDliTk5XU1R4RUMtb2c1WDZxWHNENmc6MQ#gid=0 >> " >> myArray = %w[test one two three] >> b = Watir::Browser.new :firefox, :profile => 'LoL' >> b.goto url >> contents = Array.new >> contents = b.select_list(:name => 'entry.6.single').options >> puts contents[0] >> ap myArray >> b.close >> >> > On Tuesday, April 24, 2012 12:30:04 PM UTC-7, krizzo wrote: >> >> I created this test script because I was having issues with another >> script that needed to work with select_list. This is having the same issue. >> From my understanding "contents[0]" should print out "Firefox" but instead >> I get a memory location. I printed the "memory" location out and it's not a >> simple array of the options it almost looks like the browser object. >> >> I wanted to know if this was a known issue or is my understanding >> incorrect on options returning an array? >> >> ## Output >> #<Watir::Option:0x816f138> >> [ >> [0] "test", >> [1] "one", >> [2] "two", >> [3] "three" >> ] >> >> ## Test Script >> >> require 'rubygems' >> require 'ap' >> require 'watir-webdriver' >> url = " >> https://spreadsheets.google.com/viewform?hl=en&formkey=dDliTk5XU1R4RUMtb2c1WDZxWHNENmc6MQ#gid=0 >> " >> myArray = %w[test one two three] >> b = Watir::Browser.new :firefox, :profile => 'LoL' >> b.goto url >> contents = Array.new >> contents = b.select_list(:name => 'entry.6.single').options >> puts contents[0] >> ap myArray >> b.close >> >> -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected]
