In a web page we are supposed to see number of links in the application.To achieve this we require the small piece of code:
Example:
package Testng;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class countlinks {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver go=new FirefoxDriver();
go.get("https://www.google.co.in/?gws_rd=cr&ei=leSxUoeoI8qOrgfT0oCAAQ");
List<WebElement> google_links =go.findElements(By.tagName("a"));
int count =0;
for(WebElement google_link:google_links)
{
count++;
}
System.out.println(count);
}
}
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class countlinks {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver go=new FirefoxDriver();
go.get("https://www.google.co.in/?gws_rd=cr&ei=leSxUoeoI8qOrgfT0oCAAQ");
List<WebElement> google_links =go.findElements(By.tagName("a"));
int count =0;
for(WebElement google_link:google_links)
{
count++;
}
System.out.println(count);
}
}
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
No comments:
Post a Comment