Watir With Login App(Gmail)

77 views
Skip to first unread message

edipofederle

unread,
Jun 5, 2011, 9:35:45 AM6/5/11
to Watir General
Hello everyone, is my first contact with Watir and am really enjoying
it, but I have a problem to run the following test:

https:/ /gist.github.com/1008964

is a simple test that logs into a gmail account and a text verefica
(Mail) via XPath, but the test fails and says that the element was not
found, read the documentation that the Waitresses 'wait' then load the
page that I create the element is there .. Can someone ajuar me with
this?

Note: This is for an academic work and I chose it for Watir.

Chuck van der Linden

unread,
Jun 6, 2011, 5:15:48 AM6/6/11
to Watir General
my experience seems to be that in general I use xpath as a last resort
to identifying elements. it's almost impossible to read (e.g. know by
reading the code what element is being manipulated) and it tends to
break the moment anyone re-designs any portion of the page that
affects the 'path' to an object.

Far better to identify by ID or Name or some other characteristic that
is unique to the element, or a container wrapped around the element.

Secondly on pages with a lot of client side javascript, the page may
require a little bit of time from when the browser says 'the page is
done loading' (in other words, the last request of the webserver for
page content has completed) and when all objects in the DOM have
actually been created and are ready to be interacted with. In general
that means you might need a small wait (see 'how to wait with water'
<http://wiki.openqa.org/display/WTR/How+to+wait+with+Watir>) before
you start trying to interact with the page. Generally if you can
execute script steps manually a line at a time in IRB and they work,
but they fail when the entire script is run 'at machine speed' then
this kind of synchronization is the issue and you'll need to insert
some small wait delays in front of elements that are being created/
rendered via client side scripting instead of existing in the HTML as
downloaded from the website

Lastly before writing automation code against any website you do not
own, check the terms of service for the site to see how they feel
about accessing the site with automation. Many sites prohibit it in
their user agreement unless you get permission first (academic
purposes or not)

Željko Filipin

unread,
Jun 6, 2011, 5:43:03 AM6/6/11
to watir-...@googlegroups.com
On Sun, Jun 5, 2011 at 3:35 PM, edipofederle <edipof...@gmail.com> wrote:
> is a simple test that logs into a gmail account and a text verefica
> (Mail) via XPath

Instead of

@fff.cell(:xpath, '/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/div[1]/div[1]/div[@id=\':r7\']/span').text

I would try

@fff.cell(:id=> ':r7').span(:index => 1).text

Željko
--
watir.com - community manager
watir.com/book - author
watirpodcast.com - host
viaqa.mobi conference on software testing - organizer


Reply all
Reply to author
Forward
0 new messages