hyperlinkwatir

How Can I Click This Link Using Watir?


I want to navigate a site using watir. I can't find nor focus on an element to click on it. It's the Next link on top right of this url:

Companies

How can I test that the link exists and can focus on it to click it?


Solution

  • The link HTML is:

    <a id="view:_id1:_id258:pager6__Next__lnk" href="#" title="Go to next page:">Next</a>
    

    The identifiable attributes seem to be the id (being careful of the auto-generated portions) or the title. The link could be located by either:

    browser.link(title: 'Go to next page:')  # using title
    browser.link(id: /Next__lnk/)            # using partial id
    

    You can check if the link is available by checking if it is present:

    browser.link(title: 'Go to next page:').present?
    

    You can click with:

    browser.link(title: 'Go to next page:').click