Problem automating the new Excite Mail due to nested divs

11 views
Skip to first unread message

NS

unread,
Oct 9, 2008, 2:38:48 PM10/9/08
to Watir General
Hello,

I am new to Ruby and Watir and as my first assignment, I am trying to
fix the ruby script which automated the opening and browsing messages
in the Excite Mail. After Excite changed interface, the script has
been failing.

I used IE toolbar to see the underlying elements in the page and it
seems that it is lots of nested divs before you find an actual #text
which provides the visible text for the link.

I am not sure how to access the divs deep down to find the text value
I want and than click it.

The structure of HTML for "Logout" link looks like this.

<DIV class=ApplicationHeader id=ApplicationHeader>
<DIV class=NavigationBar>
<DIV class=NavigationBar_Padding>...</DIV>
<DIV class=NavigationBar_logo>...</DIV>
<DIV class=NavigationBar_buttons>...</DIV>
<DIV class=NavigationBar_extra>
<DIV class=NavigationBar_Search>
<DIV class=NavigationBar_Links>
<DIV class=NavigationLink>...</DIV>
<DIV class=NavigationLink>...</DIV>
<DIV class=NavigationLink>...</DIV>
<DIV class=NavigationLink>
<DIV class=NavigationLink_Icon>...</DIV>
<DIV class=NavigationLink_text>
#text

I tried following but it didn't work.

if ($ie.div(:id, "ApplicationHeader").div(:index,
1).div(:index,4).div(:index,2).div(:index,4).div(:text,/
Logout/).exists?)
thr = Thread.new{$ie.div(:id,
"ApplicationHeader").div(:index,1).div(:index,4).div(:index,
2).div(:index,4).div(:text,/Logout/).click}
if (thr.join(MaxPageLoadWait).nil?)
thr.exit
end
debug "Clicked logout link"
end

I am able to find the div ApplicationHeader using following

$ie.div(:id, "ApplicationHeader")


Any help would be highly appreciated.

Thanks,
Nisha

Nathan Lane

unread,
Oct 9, 2008, 5:15:33 PM10/9/08
to watir-...@googlegroups.com
On thing about Watir is that it generally does what the browser does, so if you really click on a DIV to perform an action on a web site, then using Watir click on the DIV. This may be the case here with your situation, though I am not certain how Excite Mail is actually structured (your HTML example is obviously trimmed down quite a bit), and I don't see and links (<A HREF="...">...</A> tags). Anyway for example, if I have a DIV that is like this:

<div class="navigationLink" onclick="javascript: logMeOut();">Logout</div>

Then I could just go

div(:class, "navigationLink").click

likewise let's say that I have this structure, and no other "links" are located under it. i.e. this is the exact structure:

<div class="navigationLink" onclick="javascript: logMeOut();">
  <div>
    <div>
      <div>
        Logout
      </div>
    </div>
  </div>
</div>

Then I can still do

div(:class, "navigationLink").click

and the browser will feel the click down at the bottom..actually it feels it at the top, but the link the user would see is at the bottom.

Nathan

NS

unread,
Oct 9, 2008, 5:44:43 PM10/9/08
to Watir General
Nathan,

Thanks for your reply.

There is no actual <A> tag that I see in the IE toolbar.

The HTML structure that I have posted with original message is the one
I see in IE toolbar and the places where I have put "..." between
<DIV> tags..there are more divs there.I don't know how to attach a
screenshot here otherwise I can attach the Excite Mail page and you
can see how things are rendered.

Also I was wondering how div(:class, "NavigationLink") would find the
"Logout" link only because there are other divs defined with the same
class.

Thanks,
Nisha

Nathan Lane

unread,
Oct 10, 2008, 10:35:18 AM10/10/08
to watir-...@googlegroups.com
You might have to do

div(:class => "NavigationLink", :index => 4).click

The :index is 1-based, so the fourth link would be index = 4. This is one of the really helpful features of Watir, namely multiple attributes so that you can define exactly which element to click on or manipulate more specifically.

Nathan

NS

unread,
Oct 10, 2008, 4:12:31 PM10/10/08
to Watir General
Hi Nathan,

Thanks for your help. This one worked. But it is not consistent. It
works few times and it doesn't work the next time.

Also I am trying the same approach for another "INBOX" link and it is
giving message unable to find element using
class=>"LiteTreeNode", :index=>1.

Also is there a way for me to check if
div(:class=>"NavigationLink", :index=>4) returns the "Logout" text or
something else. Just to confirm that whatever I am clicking is the
right one.

Thanks once again for all your help.

- Nisha
Reply all
Reply to author
Forward
0 new messages