# Before 'click' in WATIR

**URL:** <https://www.ruby-forum.com/t/before-click-in-watir/78362>\
**Category:** Ruby\
**Created:** [December 5, 2006, 10:46am UTC](https://www.ruby-forum.com/t/before-click-in-watir/78362 "2006-12-05T10:46:45Z")\
**Posts on this page:** 3\
**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, 10:46am UTC](https://www.ruby-forum.com/t/before-click-in-watir/78362/1 "2006-12-05T10:46:45Z")

</div>

I am using code below to click in a page when it finds “Next” link.

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

But as many of you know, many web pages have these next links that goes  
on and on, but when it reaches the last pages, it no longer has link  
although the text “Next” is present.

So “Next” is present but link is no longer present.

If WATIR code still ask for “ie.link(:text, “Next”).click” in the last  
page, I would get error message at this point.

Is there anyway, I can start this “ie.link(:text, “Next”).click” only  
after checking whether the link is present or not??

So when it reaches the last page, although “Next” text is present, if  
link is not present, then rather than producing error message, stop the  
code, and go to the next process…

any help will be deeply appreciated…

---

<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, 7:16pm UTC](https://www.ruby-forum.com/t/before-click-in-watir/78362/2 "2006-12-05T19:16:18Z")

</div>

On Dec 5, 2006, at 1:45 AM, curious wrote:

> any help will be deeply appreciated…

Curious-

```
I don't know much about watir but I think you could easily just

```

rescue the exceptions that watir throws when the Next link is  
disabled. So run your current program again and look at what kind of  
exception it raises. Then you can rescue that exception and move on  
to the next set of pages:

```
I don't know what error you get exactly, lets assume its

```

WatirException(i’m sure its not called this but you get the idea)

begin  
ie.link(:text, “Next”).click  
rescue WatirException  
#code to move to the next set of pages  
end

Cheers-

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<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, 8:16pm UTC](https://www.ruby-forum.com/t/before-click-in-watir/78362/3 "2006-12-05T20:16:26Z")

</div>

Assuming the variable containing the Watir::IE controller is called  
“$ie”…

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

puts(“No more “Next” buttons”)
