Selenium WebDriver - unable to close dropdown menu in Chrome on Mac OS X

I have been working with Selenium WebDriver for several months now, and I have a problem with a drop-down menu in the web application I'm working on.

What happens is that the test opens the page, checking several elements on the page, finding them, and then ensuring that they are displayed. After that, text is entered into the text fields, and then the options window opens to open the drop-down menu. After that, the test iterates through all the parameters in the drop-down menu until it finds the right one, then clicks on this option.

At this point, an option is selected, but the drop-down menu does not close.

I tried to click on the selection selector again, but this has no effect, other pages will move during the rest of the test, and the menu will not close.

Then the page is saved and then moved away from it. However, the drop-down menu remains until the browser closes.

This is the code from the application:

<select id="options" name="options" class="options"> <option value="option1 (auto)">option1 (auto)</option> <option value="option2">option2</option> <option value="option3">option3</option> </select> 
+6
source share
3 answers

I solved the problem with work, as this is the only way I found a job.

Firstly, thank you, Evgeny .polschikov for your answer, although he did not solve the problem, it opened my eyes somewhat, I did not know what to do with the action creator, and this gave me great ideas about future tests. Also thanks to everyone who read this and thought about a possible solution.

The workaround that is now being applied is that the selection does not open. The way the code works is that it will open the list and find the one that it needs, and click on it, and at that moment the selection will not be closed, so now the code no longer opens the selection in the first place, it clicks the hidden option to choose it, not 100% what I wanted, but it works.

Happy programming, Ben.

+1
source

The first solution I will try is to click on the menu options in different ways. Selenium API gives us this opportunity. 1) find, for example. css element selectors.

 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, do not forget to check whether you found the elements correctly, for example, in firepath, firebug addon in ffox: proper location on web element in firepath

approach 1

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

approach 2 using action API

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

you can get more information about the action constructor here

approach 3 using jsExecutor to click a 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.

+2
source

If a person can press Escape to exit combobox, you can do this 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) 
0
source

Source: https://habr.com/ru/post/927192/


All Articles