Selenium click on link

khalid13 picture khalid13 · Jul 3, 2012 · Viewed 13.2k times · Source

I'm using Selenium's IDE in FireFox to do some testing, and I want Selenium to click the second link (Text2). Any idea how I do that? Unfortunately I don't have access to the HTML and can't modify it. The record function doesn't seem to register the click.

The code is attached below. Thanks in advance!

<div class="class1">
    <div class="class2">
        <span class="class3"><a href="#" onclick="fn1();">Text1</a></span>
    </div>
</div>

<div class="class1">
    <div class="class2">
        <span class="class3"><a href="#" onclick="fn2();">Text2</a></span>
    </div>
</div>

Answer

Roddy of the Frozen Peas picture Roddy of the Frozen Peas · Jul 3, 2012

Selenium supports the link=Link Text locator as well. If you know the exact link text, you can use this locator, but not otherwise. So for your examples above: link=text2 or link=View Previous Statements. (See this site and this site for other locators.)