Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium click on link

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>
like image 201
khalid13 Avatar asked Jul 03 '12 12:07

khalid13


People also ask

How do you click on a link in Selenium?

To click a link, we can use the link text locator which matches the text enclosed within the anchor tag. We can also use the partial link text locator which matches the text enclosed within the anchor tag partially. NoSuchElementException is thrown if there is no matching element found by both these locators.

Where is xpath for href link in Selenium?

This will get you the generic link: selenium. FindElement(By. XPath("xpath=//a[contains(@href,'listDetails.do')")).

How do I click a link in Selenium Python?

We can click on a link using Selenium webdriver in Python. A link is represented by the anchor tag. A link can be identified with the help of the locators like - link text and partial link text. We can use the link text attribute for an element for its identification and utilize the method find_element_by_link_text.

How to click on a link on page in selenium?

We can click on a link on page with the help of locators available in Selenium. Link text and partial link text are the locators generally used for clicking links. Both these locators work with the text available inside the anchor tags. Link Text – The text within the anchor tag is matched with the element to be identified.

What is the purpose of click command in Selenium IDE?

click is one of the commands in Selenium IDE. The purpose of click command in Selenium IDE, is to click on any UI element in the application. In this article, I am going to practically demonstrate click command in Selenium IDE for clicking the below-shown link on the page:

What is click interaction in selenium automation?

One of the most fundamental and crucial interactions while Selenium automation testing is done by automating click operations over elements on a web page. We facilitate the click interaction using a method called Selenium.click (). Selenium click button method, although, is one of the most basic drills, it is often used inefficiently.

How to perform a click in selenium using locators?

Let’s see how you can perform a click in Selenium using different Locators. 1. ID () Wherever an ID is specified in the HTML code for any web element, you can leverage that in your Selenium automation testing scripts to locate that particular web element.


2 Answers

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.)

like image 199
Roddy of the Frozen Peas Avatar answered Oct 23 '22 05:10

Roddy of the Frozen Peas


You Can Try

//a[contains(text(),'text2')]     OR  //span/a[contains(text(),'text2')]


Looking for same or anything else?

like image 21
Rohit Ware Avatar answered Oct 23 '22 04:10

Rohit Ware