1

I am using Selenium to run tests on a page with multiple drop-down menus (specifically a pop-up page which allows you to select some options then close it). I am able to click on some of these menus totally fine; however, some of them throw an ElementNotInteractable exception with the message "element could not be scrolled into view", even though the menus are right beside each other. I am very confused as to why one menu works and the other does not even though they appear to be the same. The three things I have tried in order to click on the menu are:

a) Regular Selenium clicking :

driver.findElement(By.xpath("//select[@foo='bar']").click();


This is what works with the other menus, except I navigate directly to the "option" tag and click on it (don't need to click the drop down first)

b)Javascript executor

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);


When I use this, no exceptions are thrown; however, the menu remains empty, which leads me to believe it is not being clicked on.

c)Actions

Actions builder = new Actions(driver);
builder.moveToElement(menu).click(menu);
builder.perform();


For some reason when I use this, the whole pop-up window with the drop down menus on it closes. :/ (I have double checked that it is not the close button being clicked)


I'm not sure if this is relevant, but Selenium has no problem finding the elements, it is just when I try to click them that it complains.

To summarise, my questions are:
1) What could make the menus different such that one is clickable and one is not?
2) How can I click on the second menu and choose an option?

Edit: I tried the solution found in the similar problem; unfortunately it does not work. The solution was to add an explicit wait since the element may not have completely loaded, this only leads to a timeout.

Air_Miles
  • 51
  • 2
  • 8
  • Possible duplicate of [How to resolve ElementNotInteractableException in Selenium webdriver?](https://stackoverflow.com/questions/43868009/how-to-resolve-elementnotinteractableexception-in-selenium-webdriver) – undetected Selenium Feb 20 '18 at 04:11
  • Hi! Thanks for the link, I checked it out but unfortunately when I add an explicit wait as suggested, it just times out (no matter the maximum I put on it). – Air_Miles Feb 20 '18 at 07:34

1 Answers1

0

Using JavascriptExecutor is a workaround to interact with non interactable elements. I think it should never be used in selenium tests because it makes the test do things a real user wouldn't be able to do in a real life scenario.

The most plausible cause is that you are interacting with the wrong element, try to debug to identify the element returned by the used selector.

You can use chrome dev tools in debug mode : 1- Put a breakpoint at the exception line, 2- Use $x("//select[@foo='bar']") in the chrome console to get the element.

To select a value, you can use the org.openqa.selenium.support.ui.Select object :

new Select(element).selectByValue(value);
ibenjelloun
  • 7,425
  • 2
  • 29
  • 53
  • Hi, thanks for the answer! I tried using the Select object; however, I still get the error "element – Air_Miles Feb 21 '18 at 00:44
  • Yes, that's probably what's happening. – ibenjelloun Feb 21 '18 at 06:53
  • Ok I'll keep looking into that, I've tried to click on various levels but hopefully I missed something! Thank you :) I'll update here if that ends up working – Air_Miles Feb 21 '18 at 18:03