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>
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.
This will get you the generic link: selenium. FindElement(By. XPath("xpath=//a[contains(@href,'listDetails.do')")).
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.
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.
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:
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.
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.
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.)
You Can Try
//a[contains(text(),'text2')] OR //span/a[contains(text(),'text2')]
Looking for same or anything else?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With