On Oct 12, 9:11 am, Joe Fleck <[email protected]> wrote:
> Hi Željko,
>
> Thank you for getting me started.
>
> I have developed the following code but I an still falling short of getting
> the value property.
>
> lists = $browser.div(:class,'add-themes').lis
>
> lists.each do |li|
>
> puts chckbx = li.text
>
> $browser.div(:class,'add-themes').label(:text,chckbx).click
>
> end
>
> here is what I have for checkboxes
>
> checkboxes = $browser.div(:class,'add-themes').checkbox
>
> checkboxes.each do |checkbox|
>
> puts chckbxValue = checkbox.value
>
> end
>
> It errors out.
>
> undefined method `each' for #<Watir::CheckBox:0x10d530f30>
>
> from
> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/elements/element.rb:295:in
> `method_missing'
>
> from (irb):99
>
> from
> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/selenium-webdriver-2.7.0/lib/selenium/webdriver/firefox/binary.rb:48
>
> I can click on the label for the checkbox but I can't seem to retrieve those
> values.
>
Your problem is that you are trying to call the .each method on a
single checkbox, not a collection of checkboxes. There error is a
missing 's' character at the end of this line
checkboxes = $browser.div(:class,'add-themes').checkbox
That's going to return the first checkbox with that class, not a
collection of ALL checkboxes with that class
Secondly, it's a stylistic thing mostly I suppose, but I have to ask,
why write it this way
checkboxes = $browser.div(:class,'add-themes').checkbox
checkboxes.each do |checkbox|
Instead of just using this
$browser.div(:class,'add-themes').checkboxs.each do |checkbox|
Also in the inner loop, why do
puts chckbxValue = checkbox.value
instead of
puts checkbox.value
The biggest testability problem I see with your code is that your list
items have no easy means to identify them, and the checkboxes have no
text, but rather a label defined in parallel within the list item.
Maybe someone else can find a more elegant means of doing this, but I
suspect you may need to make use of the .parent method, using perhaps
something along this line
davalue = browser.label(:text, "Ambulatory/Outpatient
Care").parent.checkbox.value
That should work if the objective is to get the value for a known
label. If you are trying to build up some kind of list of
labels&values then you could do something similar to this
browser.lis.each_with_index do | li, i|
puts i
puts li.label.text.inspect
puts li.checkbox.value
end
--
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]