select an dropdown element selenium java



  • enter image description hereclicking on service provider exposes a submenu and i need to select one of the options in the submenu. i keep getting not interactableas error...

    org.openqa.selenium.ElementNotInteractableException: element not interactable (Session info: chrome=73.0.3683.86) (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Mac OS X 10.14.0 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'



  • What you need to do is, create separate WebElement variables for each action in the dropdown, for example, the main element is "Drinks", its submenu is "Non-Alcoholic" & its submenu is "RedBull".

    So for this, there will be 3 separate WebElements, and perform click event using Actions. You can perform as many clicks as you want. And an answer to your question is to add sleep between the clicks. That thing worked for me.

        WebElement Food = driver.findElement(By.xpath("//*[@id='main-menu']/div/ul/li[11]/a"));
        WebElement Drinks = driver.findElement(By.xpath("//*[@id='drinks']/span[1]"));
        WebElement RedBull = driver.findElement(By.xpath("//*[@id='redbull']/span[1]"));
    
        Actions action = new Actions(driver);
        action.moveToElement(Food).click().moveToElement(Drinks).click().build().perform();
        Thread.sleep(200);
        action.moveToElement(RedBull).click().build().perform();
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2