Watir: links with similar text in a page. How to access?

Hi All,

I need Help!
In a page I am having two section(windows and linux) with has some
installation instructions. This "Installation instruction" text link
which calls some javascript functions are placed twice in the page (once
under Windows and once under linux).
With the command "ie.link(:text, /Installation instruction/).click" I am
only able to click the first occurance of the text, under windows. How
to click the second instance of the same text(i.e, Installation
instruction) link, under linux?.

Thanks in advance,
Mandeep

···

--
Posted via http://www.ruby-forum.com/.

Maybe if you send the HTML, more people can help.
The general idea is that you would have to first reach an enclosing
element (like a div or a frame) and then search in that constraint.

···

-----Original Message-----
From: mbaruah@spikesource.com [mailto:mbaruah@spikesource.com]
Sent: Monday, November 10, 2008 4:13 PM
To: ruby-talk ML
Subject: Watir: links with similar text in a page. How to access?

Hi All,

I need Help!
In a page I am having two section(windows and linux) with has
some installation instructions. This "Installation
instruction" text link which calls some javascript functions
are placed twice in the page (once under Windows and once
under linux).
With the command "ie.link(:text, /Installation
instruction/).click" I am only able to click the first
occurance of the text, under windows. How to click the second
instance of the same text(i.e, Installation
instruction) link, under linux?.

ie.link(:text => /Installation instruction/, :index => 2).click

···

On Mon, Nov 10, 2008 at 4:43 AM, Mandeep Baruah <mbaruah@spikesource.com>wrote:

Hi All,

I need Help!
In a page I am having two section(windows and linux) with has some
installation instructions. This "Installation instruction" text link
which calls some javascript functions are placed twice in the page (once
under Windows and once under linux).
With the command "ie.link(:text, /Installation instruction/).click" I am
only able to click the first occurance of the text, under windows. How
to click the second instance of the same text(i.e, Installation
instruction) link, under linux?.

Thanks in advance,
Mandeep
--
Posted via http://www.ruby-forum.com/\.

--
Bret Pettichord
GTalk: bpettichord@gmail.com
CTO, WatirCraft LLC, http://www.watircraft.com
Lead Developer, Watir, http://wtr.rubyforge.org
Blog (Essays), http://www.io.com/~wazmo/blog
MiniBlog (Links), Bret's Recommendations

Sarcar, Shourya C (GE Healthcare) wrote:

some installation instructions. This "Installation
instruction" text link which calls some javascript functions
are placed twice in the page (once under Windows and once
under linux).
With the command "ie.link(:text, /Installation
instruction/).click" I am only able to click the first
occurance of the text, under windows. How to click the second
instance of the same text(i.e, Installation
instruction) link, under linux?.

Maybe if you send the HTML, more people can help.
The general idea is that you would have to first reach an enclosing
element (like a div or a frame) and then search in that constraint.

Attaching the portion of HTML that concerns. As described, I need to
click on the second text link, "Installation instructions".

Attachments:
http://www.ruby-forum.com/attachment/2910/Watir-text-link.html

···

--
Posted via http://www.ruby-forum.com/\.

Bret Pettichord wrote:

ie.link(:text => /Installation instruction/, :index => 2).click

Thanks Bret, that worked and I was looking for that exactly.
Thanks, Shourya for your your time and help.

···

--
Posted via http://www.ruby-forum.com/\.

If you have any control over the generation of that HTML, you should
change it to be more structured.
Otherwise, a quick and dirty way would be:

ie.links.each {|link| link.click if link.text =~ /Installation/}

···

-----Original Message-----
From: mbaruah@spikesource.com [mailto:mbaruah@spikesource.com]
Sent: Monday, November 10, 2008 6:00 PM
To: ruby-talk ML
Subject: Re: Watir: links with similar text in a page. How to access?

Attaching the portion of HTML that concerns. As described, I
need to click on the second text link, "Installation instructions".

Attachments:
http://www.ruby-forum.com/attachment/2910/Watir-text-link.html