2
private void select(WebDriver driver, String select_text) {
    System.out.println("Selecting "+select_text+" from drop down menu");
    Select select = new Select(driver.findElement(By.name("roomMenu")));
    select.selectByVisibleText(select_text);
}

This function works fine with firefox, but when running in IE, it doesn't click on any option. Is there a specific way I have to do it for IE?

EDIT:
I rewrote it without using the Select object and it still refuses to click the option.

private void select(WebDriver driver, String select_text) {
    System.out.println("Selecting "+select_text+" from drop down menu");

    WebElement select = driver.findElement(By.name("roomMenu"));
    List<WebElement> options = select.findElements(By.tagName("option"));

    for (WebElement option : options) {
        if (option.getText().equals(select_text)) {
            System.out.println(option.getText());
            option.click();
        }
    }
}

It prints out the correct option so I know it found the right one, but when I do option.click() nothing happens in IE.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Takkun
  • 6,131
  • 16
  • 52
  • 69

1 Answers1

2

I use -

private boolean selectFromDropDown(String locator, String value) {
    try {
        new Select(driver.findElement(By.xpath(locator))).selectByVisibleText(value);
        return true;
    }
     catch (Exception e) {
            verificationErrors.append(e.toString());
            System.out.println("Could not find element");
            return false;
        }
}

Works fine in IE too! Got it from here.

Community
  • 1
  • 1
some_other_guy
  • 3,364
  • 4
  • 37
  • 55