Selenium WebDriver - Unable to close select drop down menu in Chrome on Mac OS X Selenium WebDriver - Unable to close select drop down menu in Chrome on Mac OS X google-chrome google-chrome

Selenium WebDriver - Unable to close select drop down menu in Chrome on Mac OS X


the first solution I would try is to click on menu options in different ways. Selenium API provides us with this possibility.1) locate e.g. css selectors of the elements.

String cssOption1 = "select[id='options']>option[value='option1 (auto)']";String cssOption2 = "select[id='options']>option[value='option2']";String cssOption3 = "select[id='options']>option[value='option3']";

Also don't forget to verify that you found elements properly e.g .in firepath, firebug addon in ffox:proper location on web element in firepath

approach 1

driver.findElement(By.cssSelector(cssOption2)).click();

approach 2 using actions builder API

WebElement mnuOptionElement;mnuOptionElement = driver.findElement(By.cssSelector(cssOption2));Actions builder = new Actions(driver);// Move cursor to the Main Menu Elementbuilder.moveToElement(mnuOptionElement).click();

more info about Actions builder you can get here

approach 3 using jsExecutor to click on web element. Always works for me in all situations.

JavascriptExecutor js = (JavascriptExecutor) driver;        StringBuilder stringBuilder = new StringBuilder();        stringBuilder.append("var x = $(\'"+cssOption2+"\');");        stringBuilder.append("x.click();");        js.executeScript(stringBuilder.toString());

Hope this works for you


I have solved the problem with a work around, as this is the only way that I have found to work.

Firstly thank you eugene.polschikov for your answer although it didn't solve the problem it did open my eye somewhat, I had no knowledge of action builder, and it has given me some great ideas about future tests. Also thank you to anyone who read this and pondered over a possible solution.

The workaround that is now in place is that the select is not opened.The way the code works is that it would open the list and find the one it wanted and click on it, at this point the select wouldn't close, so now the code no longer opens the select in the first place, it clicks on the hidden option to select it, not 100% what i wanted, but it works.

Happy Programming,Ben.


If a human can press Escape to exit the combobox, you can do that in Selenium by switching to the active element:

    from selenium.webdriver.common.keys import Keys     element = driver.switch_to.active_element    element.send_keys(Keys.ESCAPE)