How to Click Link by URL in Robot Framework

Jamie picture Jamie · Mar 24, 2017 · Viewed 26.4k times · Source

In the [Selenium2 Robot Framework documentation][1], the guide to Click Link is:

Clicks a link identified by locator. Key attributes for links are id, name, href and link text. See introduction for details about locating elements.

I have tried different ways to insert the URL using the href tag but I still could not get it work. May I have an example on doing this please? I could not use link text as I have multiple links with the same text (unfortunately named "Create") and they do not have any element id for me to reference.

I got this error:

ValueError: Element locator with prefix 'href' is not supported

Thanks in advance!

Here's my code:

*** Settings ***
Library           Selenium2Library

*** Test Cases ***
Test1
    [Documentation]    Try to login
    Open Browser    {my login page by i cant post more than 2 links here. it's working fine here}    CHROME
    Input Text    //*[@id="rightColum"]/table/tbody/tr/td[2]/table/tbody/tr/td/form/table/tbody/tr[1]/td[2]/input    username
    Input Password    //*[@id="rightColum"]/table/tbody/tr/td[2]/table/tbody/tr/td/form/table/tbody/tr[2]/td[2]/input    password
    Click Button    //*[@id="Login2"]
    Click Link    href=https://test/enquire.aspx

Answer

Bas van Stein picture Bas van Stein · Mar 24, 2017

The following should both work fine:

Click Link       href=http://link.com

Click Link       xpath=//a[@href="http://link.com"]

But if there is an = sign in your link, the first option will not work. You should add default= in front of href= to fix that.