Advertisement
SeleniumETrainR

Example - How to get all links of selected area of webpage w

Dec 21st, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.List;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7.  
  8.  
  9. public class ExampleOLXClassifieds {
  10.  
  11.      
  12.     public static void main(String[] args) {
  13.          
  14. WebDriver myTestDriver = new FirefoxDriver();
  15.        
  16.         myTestDriver.manage().window().maximize();
  17.        
  18.         myTestDriver.navigate().to("http://www.olx.in/");
  19.        
  20.         List<WebElement> link_boxes= myTestDriver.findElements(By.xpath("//div[@id='home']/div[@class='column']"));
  21.         System.out.println("Number of boxes "+link_boxes.size() );
  22.        
  23.         for(int j=0;j<link_boxes.size();j++){
  24.            
  25.             WebElement box = link_boxes.get(j);
  26.             List<WebElement> links = box.findElements(By.tagName("a"));
  27.             System.out.println("Total links for---"+(j+1)+"---are--- "+ links.size() );
  28.            
  29.             for(int i=1 ; i<links.size();i++){
  30.                 System.out.println("*********************************************");
  31.                 System.out.println(links.get(i).getText());
  32.                 System.out.println(links.get(i).getAttribute("href"));
  33.                
  34.             }
  35.         }
  36.  
  37.         myTestDriver.quit();
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement