package seleniumLearnWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AllLinkNames {
WebDriver driver;
@Test
public void DisplayAllLinksNames() {
driver.get("http://seleniumlearn.com/");
List<WebElement> alllinks= driver.findElements(By.tagName("a"));
for(WebElement link:alllinks)
System.out.println(link.getText());
}
// OR
@Test
public void AllLinkName() throws Exception {
driver.get("http://www.seleniumlearn.com");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Number of Links in the Page is " + links.size());
for (int i = 1; i<=links.size(); i=i+1) {
System.out.println("Name of Link# " + i + links.get(i).getText());
}
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
//System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe"); //--->chrome browser path
//driver=new ChromeDriver();
}
}