Friday, 27 December 2013

Selenium Webdriver - How To get options of Dropdown -Example


WebDriver driver1 = new FirefoxDriver();
driver.navigate().to("http://www.tizag.com/htmlT/htmlselect.php");
WebElement dropdown = driver.findElement(By.xpath("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div[4]/select"));
  Select value = new Select(dropdown);
  List<WebElement> options =  value.getOptions();

   for(int i=0;i<options.size();i++)
  {
  String ValueToFind="Colorado -- CO";
  String OptionValue;
  OptionValue=options.get(i).getText();
  if(OptionValue.contains(ValueToFind))
  {
  System.out.print("Option is present ");
  }

  }

3 comments:

  1. I'm struck in upload image/list to my project using selenium. searched in number of site no luck.

    please advise me.

    ReplyDelete
    Replies
    1. Hi Satish,

      Selenium do support file upload ,but not sure which approach you took up for bulk upload so would suggest to share some details if you can.

      Delete
    2. hello priyanka,how to write test cases for selecting dropdown list in ruby using selenium

      Delete