Works fine. Thank you, Jirka

Zeljko Filipin <[EMAIL PROTECTED]> wrote:
Try this:
 
irb(main):015:0> messages = /You have (\d)+ unread messages/.match(ie.text)
=> #<MatchData:0x2d4d938>
irb(main):016:0> messages[0]
=> "You have 0 unread messages"
 
(\d)+ means one or more digits.
 
If you need only number of unread messages:
 
irb(main):008:0> number = /(\d)+/.match(messages[0])
=> #<MatchData:0x2d67468>
irb(main):009:0> number[0]
=> "10"
 
Zeljko


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jirka Machotka
Sent: Tuesday, November 29, 2005 1:53 PM
To: [email protected]
Subject: [Wtr-general] How to read data from a web page?

Hello,
 
I'm playing around with WATIR and here is my problem:
 
#test::unit includes
require 'test/unit'
require 'test/unit/ui/console/testrunner'
require 'watir/testUnitAddons'
require 'watir'
ie = Watir::IE.new
ie = Watir::IE.start("http://mail.yahoo.com")
test = ie.contains_text("You have")
if !test
  ie.text_field(:name, "login").set("jirmac2003")
  ie.text_field(:name, "passwd").set("*********")
  ie.button(:value, "Sign In").click
end
a = ie.contains_text("You have")
if !a
  puts "Test failed!"
else
  puts "Test passed."
end
 
This program tries to log into my yahoo mail account, which works fine. But what can I do to read the number of my new emails? The relevant part of the html looks as follows:
 
<tr><td valign="top">
<h2 style="margin-bottom:8px;">
                        Welcome, Jiri!
</h2>
<img src=""http://us.i1.yimg.com/us.yimg.com/i/nt/ic/ut/bsc/mail16_1.gif">http://us.i1.yimg.com/us.yimg.com/i/nt/ic/ut/bsc/mail16_1.gif" width=16 height=16>
                        You have <b>0 unread messages</b>:<br>
</td>
</tr>
 
Is there any command in WATIR that would allow me to read this info directly? Or do I need to use other libraries (e.g. DOM) to parse the content? If the latter, would it be possible to get an example how WATIR and DOM (or anything similar) are integrated?
 
Thanks, Jirka

Yahoo! Music Unlimited - Access over 1 million songs. Try it free. _______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to