Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Watir, XML,
Espen Falkevik
6/16/2005 1:58:00 PM
I use the Watir extension to generate automated test
for web pages. To control the test results I retrieve
information from the same web page, but I get the
information from a XML-file.
I use the REXML extension, and when the XML file is
saved on my computer I can retrieve the values from it
using XPath.
How can I get the values from the XML-file, so that I
can compare it with the value I set?
Code:
require 'watir'
require 'rexml/document'
include REXML
ie = Watir::IE.start("
http://x.x.x.x/site...
)
# ie.show_all_objects
# change one value in the dropdown list
ie.select_list(:name,
"/Configuration/Audio/Inputs/Headset/Level").select_value("7")
puts "Value changed"
#saves
ie.link(:id, "").fire_event("onclick")
# open another browser and get's the xml-file
ie2 =
Watir::IE.start("
http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/L...
)
doc = ie2.document()
#try to use XPath to retrieve the value
node =XPath.first( doc,
"*/Configuration/Audio/Outputs/Headset/Level").get_text.value
The last line gives an error in the xpath_parser
(method_missing)
Hope someone can help me
-espen-
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling
worldwide with voicemail
http://uk.messenger...
___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos
http://uk.photos...
3 Answers
james_b
6/16/2005 3:27:00 PM
0
Espen Falkevik wrote:
> ...
> # open another browser and get's the xml-file
> ie2 =
> Watir::IE.start("
http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/L...
)
> doc = ie2.document()
What sort of object are you expecting ie2.document() to return?
The call to XPath.first expects a REXML Document object; the WATIR docs
really don't say much on this (it only says that document() returns the
current document. )
But grepping the WATIR source code does not show any references to
REXML, so it appears you'll need to first convert the IE document or
content to a REXML Document object.
Calling ie2.html gets you the DOM rendering of the document HTML; it's
*not* the same as the HTML sent to the browser. If it is not already
XML (and imagine it is not) you'll need to fix it up. Take a look at
Michael Neumann's Mechanize library for some ways to do this. His code
fetches HTML pages and exposes the content via a nice API over an REXML
document.
http://rubyforge.org/pr...
James
--
http://www.ru...
- The Ruby Documentation Site
http://www.r...
- News, Articles, and Listings for Ruby & XML
http://www.rub...
- The Ruby Store for Ruby Stuff
http://www.jame...
- Playing with Better Toys
Espen Falkevik
6/17/2005 8:15:00 AM
0
Hi
I looked at this project, but I can't seem to find the
examples/code that can help me...
Can anyone tell me how to fetch the HTML code and
convert it into a REXML document?
-Espen-
--- James Britt <james_b@neurogami.com> wrote:
> Espen Falkevik wrote:
> > ...
> > # open another browser and get's the xml-file
> > ie2 =
> >
>
Watir::IE.start("
http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/L...
)
> > doc = ie2.document()
>
>
> What sort of object are you expecting ie2.document()
> to return?
>
> The call to XPath.first expects a REXML Document
> object; the WATIR docs
> really don't say much on this (it only says that
> document() returns the
> current document. )
>
> But grepping the WATIR source code does not show any
> references to
> REXML, so it appears you'll need to first convert
> the IE document or
> content to a REXML Document object.
>
> Calling ie2.html gets you the DOM rendering of the
> document HTML; it's
> *not* the same as the HTML sent to the browser. If
> it is not already
> XML (and imagine it is not) you'll need to fix it
> up. Take a look at
> Michael Neumann's Mechanize library for some ways to
> do this. His code
> fetches HTML pages and exposes the content via a
> nice API over an REXML
> document.
>
>
http://rubyforge.org/pr...
>
>
>
> James
> --
>
>
http://www.ru...
- The Ruby Documentation
> Site
>
http://www.r...
- News, Articles, and
> Listings for Ruby & XML
>
http://www.rub...
- The Ruby Store for Ruby
> Stuff
>
http://www.jame...
- Playing with Better
> Toys
>
>
___________________________________________________________
How much free photo storage do you get? Store your
holiday
snaps for FREE with Yahoo! Photos
http://uk.photos...
___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos
http://uk.photos...
james_b
6/17/2005 2:04:00 PM
0
Espen Falkevik wrote:
> Hi
> I looked at this project, but I can't seem to find the
> examples/code that can help me...
> Can anyone tell me how to fetch the HTML code and
> convert it into a REXML document?
The project is Mechanize (though it is listed on the same main page as
the Wee project; really should get its own page, Michael!).
You can install Mechanize using rubygems.
This example logs into rubyforge.org, using values passed at the command
line:
require 'mechanize'
agent = WWW::Mechanize.new {|a| a.log = Logger.new(STDERR) }
page = agent.get('
http://rubyforge...
)
link = page.links.find {|l| l.node.text =~ /Log In/ }
page = agent.click(link)
form = page.forms[1]
form.fields.find {|f| f.name == 'form_loginname'}.value = ARGV[0]
form.fields.find {|f| f.name == 'form_pw'}.value = ARGV[1]
page = agent.submit(form, form.buttons.first)
puts page.root.class
img_alt = REXML::XPath.first( page.root, "//img" ).attributes[ 'alt' ]
p img_alt
The 'root' method of the Page instance returns a REXML Document.
James Britt
--
http://www.ru...
- The Ruby Documentation Site
http://www.r...
- News, Articles, and Listings for Ruby & XML
http://www.rub...
- The Ruby Store for Ruby Stuff
http://www.jame...
- Playing with Better Toys
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Watir, XML,
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password