Selenium webdriver count total number of links and print all links in a webpage
---------------------------------
package advancedWebdriver;
import java.util.ArrayList;
import java.util.List;
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.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class PrintAllLinks {
public WebDriver driver;
@Test
public void f() {
// String s[]=new String[10]; //Array
// List s1=new ArrayList(); //list
driver.get("http://spicejet.com");
List str=driver.findElements(By.tagName("a"));
System.out.println(str.size());
for (int i = 0; i < str.size(); i++) {
System.out.println(str.get(i).getText()); //str[i]
}
}
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "D:\\Library\\chromedriver.exe");
driver=new ChromeDriver();
}
@AfterTest
public void afterTest() {
}
}
No comments:
Post a Comment