element_by_xpath troubles

15 views
Skip to first unread message

keneda 45

unread,
Feb 10, 2011, 10:07:07 PM2/10/11
to Vapir
Hi every one, I'm french beginner in vapir, I use vapir because we
have a lot of special characters and vapir let me to insert them. My
problem is : I have a script which was right with watir but when I
adapt this one under vapir, it didn't worked!

..................................................................................

require 'vapir-firefox'



browser = Vapir::Browser.start "http://www.google.fr/"

#
browser.text_field(:name,"q").set("ruby")
#
browser.button(:value,"Recherche Google").click
#
puts browser.element_by_xpath("//a[@class=’l']").text


..........................................................

someone can test this script and help me to understand and resolve the
problem?

thanks a lot. Cheers

Ethan

unread,
Feb 10, 2011, 10:43:39 PM2/10/11
to va...@googlegroups.com
element_by_xpath isn't the correct API - it's an internal method of watir (absent in vapir). use :xpath as the 'how' argument to get an element:

browser.element(:xpath, "//a[@class=’l']").text

or, in a manner more in keeping with the watir api, something like:

browser.link(:class, "l").text

widizign société

unread,
Feb 11, 2011, 8:28:23 AM2/11/11
to va...@googlegroups.com
ok, thank you a lot, I understand but when I use browser.div(:xpath, "//a[@class=’l']").text, it doesn't work too. Do you think vapir will be able to integrate methods like element_by_xpath oneday?
cheers

2011/2/11 Ethan <note...@gmail.com>

Ethan

unread,
Feb 11, 2011, 11:29:01 AM2/11/11
to va...@googlegroups.com
element_by_xpath is not what you want in either case. 
You are specifying mutually exclusive criteria: in your xpath you are specifying an <a> element but you are using the #div method which will only return <div> elements. Please see the examples I provided; either one should work. 
Reply all
Reply to author
Forward
0 new messages