How to count number of visible and invisible
links present on web page?
Refer the below program
to find visible and invisible links on a web page.
package
pack2;
import
java.util.List;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
public class
VisibleInvisibleLinks {
public static void
main(String[] args) throws
InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:/path/geckodriver.exe");
FirefoxDriver driver = new
FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.co.in/");
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Total
links = "+links.size());
int count = 0;
for(int i=0;i<links.size();i++)
{
if(!links.get(i).getText().isEmpty())
{
count++;
}
}
System.out.println("Visible
links count = "+count);
System.out.println("Hidden
links count = "+(links.size()-count));
driver.quit();
}
}
No comments:
Post a Comment