ayush
ayush

Reputation: 14568

Selenium : org.openqa.selenium.ElementNotInteractableException:

This is how the HTML looks like.

<select name="ctl00$bodyContent$ddl_Territory" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$bodyContent$ddl_Territory\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_bodyContent_ddl_Territory" class="select2-container" style="margin-left: 3%;">
    <option selected="selected" value=""></option>
    <option value="675">ALASKA AK (OCRGA061A) - HCP</option>
    <option value="271">ALBANY GA (OCBDB041A) - HCP</option>
    <option value="125">ALBANY NY (OCBAA031A) - HCP</option>
    <option value="126">ALBANY NY (OCBAA032A) - HCP</option>
    <option value="426">ALBANY NY (OCRAA031A) - HCP</option>
    ....
    <option value="427">ALBANY NY (OCRAA031A) - HOSPITAL</option>

Automation code that keeps failing -

Select territory = new Select(driver.findElement(By.name("ctl00$bodyContent$ddl_Territory")));
        System.out.println("selected");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block 
           // Trying to figure if sleep is required or not.. 
            e.printStackTrace();
        }



        List<WebElement> optionList = territory.getOptions();
        for (WebElement webElement : optionList) {
            System.out.println(webElement.getText()); //this print nothing..empty line..confused
        }

        territory.selectByIndex(1); //exception thrown here

When i call selectByIndex i get org.openqa.selenium.ElementNotInteractableException: . I have tried selectByValue etc.. also but of no help. I am sure that territory points to the correct element because the optionList count is same as the number of options in HTML. However not sure why the text is not getting printed in Loop and why the exception..

Driver - geckodriver-v0.18.0-win64

TIA!

UPDATE 1: webElement.isDisplayed() print false for all options. And getLocation() prints 0,0 for both X and Y coordinates..

Upvotes: 1

Views: 579

Answers (1)

Gaurang Shah
Gaurang Shah

Reputation: 12910

The alternative way to get all the options are as below

List<WebElement> optins = driver.findElements(By.xpath("//select[@name='ctl00$bodyContent$ddl_Territory']/options"));

Alternate way to Select by visible text

driver.findElement(By.name("ctl00$bodyContent$ddl_Territory")).sendKeys("ALBANY NY (OCBAA031A) - HCP");

Upvotes: 1

Related Questions