Monday 20 February 2012

get all values from Weblist(Dropdown) in web application using selenium automation testing


importjava.io.IOException;
importjava.util.List;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.firefox.FirefoxDriver;


public class dadabhagwan_LearnSeleniumWithJasmine {

       public static voidmain(String[] args) throwsInterruptedException, IOException {
             
      
              WebDriver myDriver = newFirefoxDriver();
              myDriver.navigate().to("http://www.artofliving.org/in-en"); // main window
             
             
             
              myDriver.findElement(By.xpath("//*[@id='div-local-center-title']")).click();
              WebElement listSelectYourCenterDropdown = myDriver.findElement(By.xpath("//*[@id='edit-state-selector']"));
              List < WebElement > listSelectYourCenterOptions = listSelectYourCenterDropdown.findElements(By.tagName("option"));
              System.out.println(listSelectYourCenterOptions.size());
             
              for(int i=0 ; i
                     System.out.println(listSelectYourCenterOptions.get(i).getText()+  " ---->  "+ listSelectYourCenterOptions.get(i).getAttribute("value"));
              }
       }

}