package
Others;
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.testng.annotations.AfterTest;
import
org.testng.annotations.BeforeTest;
import
org.testng.annotations.Test;
public class
ExtractLink
{
WebDriver driver;
@BeforeTest
public void
setup() throws Exception
{
System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chromedriver_win32\\chromedriver.exe");
driver = new
ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5,
TimeUnit.SECONDS);
driver.get("http://www.google.com");
}
@AfterTest
public void
tearDown() throws Exception
{
driver.quit();
}
@Test
public void
Text() throws InterruptedException
{
try
{
List<WebElement>
no = driver.findElements(By.tagName("a"));
int nooflinks = no.size();
System.out.println(nooflinks);
for
(WebElement pagelink : no)
{
String
linktext = pagelink.getText();
String
link = pagelink.getAttribute("href");
System.out.println(linktext+"
->");
System.out.println(link);
}
}catch
(Exception e){ System.out.println("error
"+e); } }
}
No comments:
Post a Comment