On Wed, Jan 13, 2010 at 11:09 PM, Tiffany Fodor tcfo...@comcast.net wrote:
browser.link(:beforeText, 'survivors of the Haiti
earthquake.).click
I think this is deprecated because it never worked as expected.
Željko
--
watir.com - community manager
watirpodcast.com - host
--
You received this
Awesome, thanks!
I don't really need to do this right now, but this got me wondering.
Say you have two links that are exactly the same on the page (perhaps
on the header and the other in the footer). How can the use of the
array be tweaked so it can return the index number for the nth
instance of
Hi!
You could build an array of all the links and then get the index:
link_text = Array.new
browser.links.each do |link|
link_text.push(link.text)
end
link_index = link_text.index('My link text').index
To click on a link that precedes some text, you can use :beforeText.
On the current
Sorry - I forgot to mention that the array will start at 0, but the
link index number in Watir will start at 1. You could create your
array with a placeholder for 0, or add one to the index number you get
from the array when you want to access the link in Watir.
-Tiffany
On Jan 13, 3:09 pm,
Thanks for the tips.
I tried the index method using the array as you suggested. When I ran
it, I get an undefined method 'index'.
Also, when using the :beforeText or :afterText for the link, I get
unable to locate element, using :beforeText...
Any suggestions on if I'm doing something wrong?
Yikes!
I missed an ugly typo. Sorry about that - I should proof read better:
link_index = link_text.index('My link text').index
-should be-
link_index = link_text.index('My link text')
I'm not sure about the :beforeText problem - were you able to make my
www.Google.com example work?