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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mandeep B. (Guest)
on 2008-11-10 12:45
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
Sarcar, Shourya C (GE Healthcare) (Guest)
on 2008-11-10 14:10
(Received via mailing list)
> 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.
Mandeep B. (Guest)
on 2008-11-10 14:32
Attachment: Watir-text-link.html (0 Bytes)
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".
Sarcar, Shourya C (GE Healthcare) (Guest)
on 2008-11-10 16:31
(Received via mailing list)
> -----Original Message-----
> From: 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-te...
>


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/}
Bret P. (Guest)
on 2008-11-10 17:27
(Received via mailing list)
ie.link(:text => /Installation instruction/, :index => 2).click
Mandeep B. (Guest)
on 2008-11-11 08:29
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.
This topic is locked and can not be replied to.