Links

Links

You can use Watir to click links in a variety of ways. Watir can click links by looking at the link text you see in the browser or by looking at the attributes available in the <a> HTML tag. Common attributes are id, name and href. For complete list see HTML Elements Supported by Watir.

Here is an example using a link to the Pickaxe book by the Pragmatic Programmers:

What you see in the web browser:

Pickaxe

What you see in the HTML source:

<a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>

id Attribute

Watir code to click a link using the id attribute:

ie.link(:id, "one").click

name Attribute

Watir code to click a link using the name attribute:

ie.link(:name, "book").click

Text

Watir code to click a link using link's text:

ie.link(:text, "Pickaxe").click

href Attribute

Watir code to click a link using the href attribute:

ie.link(:href, "http://pragmaticprogrammer.com/titles/ruby/").click

Labels

favourite favourite Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.