Saturday, 18 February 2012

Extract all links from specific part of the webpage using webdriver for selenium automation testing


importjava.util.List;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.firefox.FirefoxDriver;


public classdadabhagwan_LearnSeleniumWithJasmine {

       public static voidmain(String[] args) throws InterruptedException {
             
              WebDriver myDriver = newFirefoxDriver();
              myDriver.get("http://satsang.dadabhagwan.org/");
             
              /*Extract all links from the webpage using selenium webdriver*/
              Listall_links_webpage = myDriver.findElements(By.tagName("a"));
             
              /*Print total no of links on the webpage*/
              System.out.println("Print total no of links on the webpage---------------------------------------------");
              System.out.println(all_links_webpage.size());
             
              /*Print text of all links*/
              System.out.println("Print text of all links------------------------------------------------------------");
              for(int i=0;i
                     System.out.println(all_links_webpage.get(i).getText());
              }
             
              /*Print Links*/
              System.out.println("Print Links------------------------------------------------------------------------");
              for(inti=0;i
                     System.out.println(all_links_webpage.get(i).getAttribute("href"));
              }
             
             
             
              /*Extract all links from the part of the webpage using selenium webdriver*/
              System.out.println("Extract all links from the part of the webpage using selenium webdriver-----------------------------");
              List< WebElement > myList = myDriver.findElement(By.xpath("//*[@id='Flot']")).findElements(By.tagName("a"));
             
              System.out.println("total no links on specific part of webpage---------------------------------------------------");
              System.out.println(myList.size());
             
              System.out.println("Text of the link for specific part of webpage--------------------------------------------------");
              for(int i =0; i< myList.size();i++){
                     System.out.println(myList.get(i).getText());

              }
             

       }

}