To Find out no of links in Home Page Using Selenium
- To Count No of Links Using tagName Locator
- Most of the Links are Developed using the Anchor code
<a href="links">link Name</a>
<a>---------->Anchor Tag.
First We have to collect all the anchor tag in WebElement using tagName Loator and stored in the List Concept(Array-java)
Then Using Size Concept to count the links and print in the console 
FindElement--->For Single Element
FindElements--->To collect Multiple Elements
public class nooflinks {     
public static void main(String[] args)
{  
WebDriver g=new FirefoxDriver();     
g.manage().window().maximize();     
g.get("");
List<WebElement>f=g.findElements(By.tagName(“a”)); 
System.out.println(“no of links
is:”f.size());   
for(int i=0;i<f.size();i++)  
{ 
System.out.println(f.get(i).getText());
 
}  
}  
} 
 
No comments:
Post a Comment