contains_text does NOT return the text

It returns the index into the text on the page where the text occurs.

You should use something like:

# get the complete text of the current page
page_text = $ie.text

# run it through a regular expression and capture the match and it's subgroups
match = /Event\# (\d+)/.match( page_text )

# if we got a result
if match != nil
  # parse those two pieces ... the match
  complete_match = match[0]
  # and the subgroup
  digits = match[1]
else
  # no match found
end




On 10/11/05, Cain, Mark <[EMAIL PROTECTED]> wrote:
> Try to_str and if that doesn't work try to_s (supported by almost all
> classes)
>
> --Mark
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of beth ferguson
> Sent: Tuesday, October 11, 2005 10:23 AM
> To: Watir Mailing List
> Subject: [Wtr-general] string split after ie.contains_text
>
> theText= $~ = $ie.contains_text(/Event\#
> ([0-9]+)([0-9]+)([0-9]+)([0-9])/)
>
> puts (theText);
>
> b = theText.split(/\d/)
>
> b.push(theText.sub(b[0],""))
>
> puts b
>
> The above snippet does not work if theText is gotten via the
> contains_text method. (I get the following error:
>
> ./createEvent.rb:40:in `userCreateEvent': private method `split' called
> for #<MatchData:0x304f3f0> (NoMethodError) from someTest.rb:88)
>
> However the snippet does work if I hand it the string ("Event# 1234").
> Is there a ToString() method or something like that , that I can use to
> make theText into a flat string rather than a method referent.
>
> Thanks-
>
> Beth
>
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>


--
"http://ruby-lang.org -- do you ruby?"

Jeff Wood

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to