Advertisement
SeleniumETrainR

How to Extract Link(s) details given on the page using selen

Dec 13th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.List;
  2. import java.util.concurrent.TimeUnit;
  3.  
  4. import org.openqa.selenium.By;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8.  
  9.  
  10. public class LinkExtractTest {
  11.  
  12.  
  13. public static void main(String[] args) {
  14. WebDriver myTestDriver = new FirefoxDriver();
  15. myTestDriver.get("http://tinyurl.com/6d7xz7k");
  16.  
  17. myTestDriver.manage().window().maximize();
  18. myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
  19. // Get all links
  20.  
  21. List<WebElement> AllPageLinks = myTestDriver.findElements(By.tagName("a"));
  22.  
  23. System.out.println(AllPageLinks.size());
  24.  
  25. for(int i =0 ; i<AllPageLinks.size();i++){
  26. if(AllPageLinks.get(i).getText()!="")
  27. System.out.println(AllPageLinks.get(i).getText());
  28. }
  29.  
  30. System.out.println("Content_Left--------------------------------------------");
  31. AllPageLinks= myTestDriver.findElement(By.xpath("//div[@id='Content_Left']")).findElements(By.tagName("a"));
  32. System.out.println(AllPageLinks.size());
  33.  
  34. for(int i =0 ; i<AllPageLinks.size();i++){
  35. if(AllPageLinks.get(i).getText()!="")
  36. System.out.println(AllPageLinks.get(i).getText());
  37. }
  38.  
  39. myTestDriver.quit();
  40.  
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement