You could probably try following these steps where first you would collect all the links of the webpage and validate them:
1) Navigate to the interested webpage.
2) Create a list of type WebElement to store all the Link elements in to it.
3) Collect all the links from the webpage. All the links are associated with the Tag ‘a‘.
4) Now iterate through every link and print the Link Text on the console screen.
package practiceTestCases;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FindAllLinks {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://edureka.co/");
java.util.List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println(links.size());
for (int i = 1; i<=links.size(); i=i+1)
{
System.out.println(links.get(i).getText());
}
}
}
The same way you can easily be able to find any type of WebElements on a WebPage:
Find total number of Menus on a Webpage :
java.util.List;WebElement> dropdown = driver.findElements(By.tagName("select"));
System.out.println(dropdown.size());
Hope this helps!