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

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.

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”.

-----Original Message-----
From: [email protected] [mailto:[email protected]]
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

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/}

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

Bret P. 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.