# Ie.link(:text, "Next").click

**URL:** <https://www.ruby-forum.com/t/ie-link-text-next-click/78456>\
**Category:** Ruby\
**Created:** [December 5, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456 "2006-12-05T23:00:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [December 5, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456/1 "2006-12-05T23:00:51Z")

</div>

I am navigating through web page using WATIR…

and as you know, many web pages has “Next” link that allows us to go to  
the next page by clicking this “Next” link.

Now when the page reaches the last page, although “Next” is present,  
but it is no longer a link.

At this point, if my code still goes to:

ie.link(:text, “Next”).click

then I get the error message…

Is there anyway I can have WATIR check whether “Next” is link or not,  
and if it is a link, then go to

ie.link(:text, “Next”).click,

and if it is just plain text, do not go to ie.link(:text,  
“Next”).click??

thanks.

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [December 5, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456/2 "2006-12-05T23:31:01Z")

</div>

curious wrote:

> ie.link(:text, “Next”).click
> 
> then I get the error message…

As others have replied to one of your other posts on this topic, why not  
trap the error using “rescue”, and move on from there?

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [December 6, 2006, 12:01am UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456/3 "2006-12-06T00:01:06Z")

</div>

could you please tell me how I can trap the error in ‘rescue’…

thanks.

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [December 6, 2006, 3:35am UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456/4 "2006-12-06T03:35:36Z")

</div>

curious wrote:

> could you please tell me how I can trap the error in ‘rescue’…

Like this:

begin

# error-creating code here

rescue

# error-handling cede here

end

Working example:

* * *

#!/usr/bin/ruby -w

begin  
x = 1/0  
rescue Exception =\> e  
puts "trapped error: " + e  
end

* * *

Output:

trapped error: divided by 0

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [December 6, 2006, 3:55am UTC](https://www.ruby-forum.com/t/ie-link-text-next-click/78456/5 "2006-12-06T03:55:40Z")

</div>

> Is there anyway I can have WATIR check whether “Next” is link or not,  
> and if it is a link, then go to
> 
> ie.link(:text, “Next”).click,
> 
> and if it is just plain text, do not go to ie.link(:text,  
> “Next”).click??

if ie.link(:text, “Next”).exists?  
ie.link(:text, “Next”).click  
end
