Yeah that's what I'm doing only I wanted to program my script as if I 
didn't know what the value in the selection would be and wanted to select 
either the nth element in the list as this code does or check the values 
and pick one.

contents = b.select_list(:xpath, "LIST").options
value = contents[1].text
b.select_list(:xpath, "LIST").select value


On Tuesday, April 24, 2012 2:45:27 PM UTC-6, Chuck van der Linden wrote:
>
> Note that if it is a multi-select list you may want to clear all the 
> selections first with the .clear method, before selecting the one(s) you 
> want to be selected.
>
> On Tuesday, April 24, 2012 1:43:18 PM UTC-7, Chuck van der Linden wrote:
>>
>> If you want to select a specific option, there's a much easier way.
>>
>> Just use the select_list's .select method
>>
>>     b.select_list(:name => 'entry.6.single').select 'Chrome'
>>
>> On Tuesday, April 24, 2012 1:34:47 PM UTC-7, krizzo wrote:
>>>
>>> I wanted to get the list of options and then have it select one of them. 
>>> Interesting that I have to include the .text to dereference the string. 
>>> That worked thanks for the help. I was searching all over trying to find 
>>> how to get the value so I could select it.
>>>
>>> krizzo
>>>
>>> On Tuesday, April 24, 2012 2:05:26 PM UTC-6, Dan wrote:
>>>>
>>>> I'm not sure what you're trying to do exactly, but you need to tell it 
>>>> you're looking for the text 
>>>>
>>>> puts contents[0].text
>>>>
>>>> You also may want to consider something like this instead of an array, 
>>>> but again I'm not really sure what you're trying to do.
>>>>
>>>> b.select_list(:name => 'entry.6.single').options.each do |opt|
>>>>   p opt.text
>>>> end
>>>>
>>>> On Tuesday, April 24, 2012 3:30:04 PM UTC-4, 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]

Reply via email to