- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to count the total number of links in a page in Selenium?
The total number of links in a page can be counted with the help of findElements() method. The logic is to return a list of web elements with tagname anchor, then getting the size of that list.
Code Implementation
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class LinkCount { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); //Using tagname with anchor List<WebElement> links = driver.findElements(By.tagName("a")); System.out.println(“The number of links is “ + links.size()); driver.close(); } }
- Related Articles
- How to count the total number of links in Selenium with python?
- How to count the total number of tables in a page in Selenium with python?
- How to count the total number of radio buttons in a page in Selenium with python?
- How to count the number of frames in a page in Selenium?
- How to get the total number of checkboxes in a page using Selenium?
- How to count the number of checkboxes in a page in Selenium with python?
- How to count the total number of frames in Selenium with python?
- How to get the total number of radio buttons on a page using Selenium?
- How to make page links in HTML Page?
- How to count the number of occurrences of a particular text inside a table in a page in Selenium with python?
- How to count the number of headers in a web table in Selenium?
- How to count the total number of lines in the file in PowerShell?
- How to count the number of rows in a table in Selenium with python?
- How to count the total number of frames in OpenCV using C++?
- How to count total number of occurrences of an object in a Python list?

Advertisements