Interview Questions

Selenium WebDriver - Count the number of links in a page.

Selenium WebDriver Interview question and Answers


(Continued from previous question...)

Selenium WebDriver - Count the number of links in a page.

use the locator By.tagName and find the elements for the tag //a then use loop to count the number of elements found.
Syntax- int count = 0; List<webElement> link = driver.findElements(By.tagName(a)); System.out.println(link.size()); // this will print the number of links in a page.


Syntax- int count = 0;

List<webElement> link = driver.findElements(By.tagName(a));

System.out.println(link.size()); // this will print the number of links in a page.

(Continued on next question...)

Other Interview Questions