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? -Tiffany On Jan 13, 3:31 pm, xguarder <shams...@gmail.com> wrote: > 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'".e > > 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? > > Thanks, > Ken > > On Jan 13, 5:12 pm, Tiffany Fodor <tcfo...@comcast.net> wrote: > > > 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, Tiffany Fodor <tcfo...@comcast.net> wrote: > > > > 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 Google page, for example: > > > > browser.link(:beforeText, 'survivors of the Haiti > > > earthquake.").click > > > > You can also use :afterText, if necessary. > > > > Hope this helps! > > > > -Tiffany > > > > On Jan 13, 2:20 pm, xguarder <shams...@gmail.com> wrote: > > > > > I was wondering if someone could inform me on how to do the following: > > > > > 1. Retrieve link index number of a link. For instance, I know I can > > > > find the link using ie.link(:text, "LinkText"), and I can also find > > > > out the index number via irb. However, I want to be able to assign the > > > > index number of that particular link to a variable on the fly. > > > > > 2. Is it possible to click on a link that immediately precedes a > > > > particular text? > > > > > Thanks!
-- You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general