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

**URL:** <https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951>\
**Category:** Ruby\
**Created:** [November 10, 2008, 11:45am UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951 "2008-11-10T11:45:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 10, 2008, 11:45am UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/1 "2008-11-10T11:45:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 10, 2008, 1:10pm UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/2 "2008-11-10T13:10:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 10, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/3 "2008-11-10T13:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 10, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/4 "2008-11-10T15:31:10Z")

</div>

> -----Original Message-----  
> From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
> 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](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/}

---

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 10, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/5 "2008-11-10T16:27:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mandeepbaruah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@mandeepbaruah](https://www.ruby-forum.com/u/mandeepbaruah)\
**Post date:** [November 11, 2008, 7:29am UTC](https://www.ruby-forum.com/t/watir-links-with-similar-text-in-a-page-how-to-access/152951/6 "2008-11-11T07:29:31Z")

</div>

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.
