your keys are the methods, so this might be what you need

> contact_controls.each do |k,v|
>    if eval(k).exists?
>       puts "its there"
>    else
>      puts "oh no"
>    end
> end



On Fri, Apr 3, 2009 at 8:06 AM, George <[email protected]> wrote:

>
> This is what I tried initially (see my first post).  Hashes do not
> allow the exists? method, and it looks like has_key? only checks the
> key in the hash (not the actual text field on the webpage).
>
> Any other ideas? :)
>
>
>
> On Apr 2, 8:23 pm, Paul Rogers <[email protected]> wrote:
> > I think ( i didnt look too hard ) that it will only see if the key is
> there,
> > this might be what you want
> >
> > contact_controls.each do |k,v|
> >    if k.exists?
> >       puts "its there"
> >    else
> >      puts "oh no"
> >    end
> > end
> >
> > Pau
> >
> > On Thu, Apr 2, 2009 at 7:58 PM, George <[email protected]> wrote:
> >
> > > Thanks, Paul!
> >
> > > For those who are interested, this part of the code worked for me:
> >
> > > contact_controls.each do |key, value|
> > >     if contact_controls.has_key?(key)
> > >       puts "PASS: Control #{value} exists."
> > >      else
> > >        puts "FAIL: Unable to locate control #{value}"
> > >      end
> > >    end
> >
> > > I thought I should ask, just to make certain: With the code I'm
> > > presenting above, does this actually check the existence of the form
> > > control, or is it merely checking that a value exists in the hash?
> >
> > > On Apr 2, 2:40 pm, Paul Rogers <[email protected]> wrote:
> > > > hash has a has_key? method
> >
> > > > Paul
> >
> > > > On Thu, Apr 2, 2009 at 3:30 PM, George <[email protected]>
> wrote:
> >
> > > > > Hello everyone,
> >
> > > > > I'm hoping this is the right forum for this question.  I'm trying
> to
> > > > > iterate through a hash and check certain text fields on a webpage:
> >
> > > > > Here is where I'm storing my controls:
> >
> > > > > controls.rb # stores the form control variables
> > > > > ===========================
> > > > > def tf_company_name
> > > > >  $tf_company_name = $ie.text_field(:id, "CompanyName")
> > > > > end
> >
> > > > > def tf_address
> > > > >  $tf_address = $ie.text_field(:id, "StreetAddress")
> > > > > end
> >
> > > > > def tf_city
> > > > >  $tf_city = $ie.text_field(:id, "City")
> > > > > end
> >
> > > > > Here is where I'm defining the iteration:
> >
> > > > > form_checks.rb # Check form controls
> > > > > ===========================
> > > > > def check_contact_form_controls
> > > > >  contact_controls = [tf_company_name => "Company Name",
> > > > >                              tf_address => "Address",
> > > > >                              tf_city => "City"]
> > > > >  contact_controls.each do |key, value|
> > > > >    if key.exists?
> > > > >      puts "PASS: Control #{value} exists."
> > > > >      else
> > > > >        puts "FAIL: Unable to locate control #{value}"
> > > > >      end
> > > > >  end
> > > > > end
> >
> > > > > Since hashes does not have an exists? method, I get an error.  Is
> > > > > there a better way to do this?
> >
> > > > > Thanks,
> >
> > > > > George
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to