I believe you are actually getting all the links from the page I think what you are seeing is that when you go to print them out you are getting the String representation of the List<WebElement> collection
. To actually see each of the links you need to iterate through the list.
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.digit.in");
java.util.List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println(links.size());
for(WebElement link : links)
{
System.out.println(link);
}
}
}
This particular format will only give you the string representation of each WebElement object.
The output looks something like this:
284
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
[[RemoteWebDriver: firefox on XP (ef74c088-1406-44e8-a40e-ec290ea4c44a)] -> tag name: a]
....
If you want to get the say the href attribute of the WebElement you can use this instead;
System.out.println(link.getAttribute("href"));