
- Selenium Tutorial
- Selenium - Home
- Selenium - Overview
- Selenium - IDE
- Selenium - Environment Setup
- Selenium - Remote Control
- Selenium - Selenese Commands
- Selenium - WebDriver
- Selenium - Locators
- Selenium - User Interactions
- Selenium - Test Design Techniques
- Selenium - TestNG
- Selenium - Grid
- Selenium Useful Resources
- Selenium - Quick Guide
- Selenium - Useful Resources
- Selenium - Automation Practice
- Selenium - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selenium - Find all Links
Testers might be in a situation to find all the links on a website. We can easily do so by finding all elements with the Tag Name "a", as we know that for any link reference in HTML, we need to use "a" (anchor) tag.
Example
import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; public class getalllinks { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.navigate().to("http://www.calculator.net"); java.util.List<WebElement> links = driver.findElements(By.tagName("a")); System.out.println("Number of Links in the Page is " + links.size()); for (int i = 1; i<=links.size(); i = i+1) { System.out.println("Name of Link# " + i + links.get(i).getText()); } } }
Output
The output of the script would be thrown to the console as shown below. Though there are 65 links only partial output is shown below.

selenium_user_interactions.htm
Advertisements