Friday, September 13, 2019

Post#31.Handling Links Part-3 (Finding All links of Header section only)

Capture all the links present on header section of an application

How to capture all the links present on header section of www.bing.com



package pack3;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CaptureLinksIn Header {

              public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:/path/geckodriver.exe");
                             FirefoxDriver driver = new FirefoxDriver();
                             driver.manage().window().maximize();
                             driver.get("http://www.bing.com/");
                            
                             WebElement header = driver.findElement(By.id("sc_hdu"));
                            
                             List<WebElement> links = header.findElements(By.tagName("a"));
                            
                             System.out.println(links.size());
                            
                             for(int i=0;i<links.size();i++)
                             {
                                           System.out.println(links.get(i).getText());
                             }
              }
}

This program will capture all links of header section.

No comments:

Post a Comment