1

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..

10
  • What are you trying to do here List<WebElement> optionList = territory.getOptions();? Thanks Commented Jul 25, 2017 at 6:57
  • Wht trying to sleep for 10 secs? try { Thread.sleep(10000); } Commented Jul 25, 2017 at 7:03
  • List<WebElement> optionList = territory.getOptions(); I was trying to get the list of options inside the Select and keep them in memory for later purposes..The sleep is something that i am experimenting on. Commented Jul 25, 2017 at 7:06
  • can you share a link on which you are working[ if possible ] ? that would be good for understanding your problem. I can try writing script on this. Commented Jul 25, 2017 at 7:15
  • Have you tried on any other browser? Commented Jul 25, 2017 at 7:40

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

2 Comments

thanks @Gaurang! The alternative way does work..any idea though on why my approach was not working?
you approach is a standard approach and should work, must be some issue with webdriver or geckdriver or firefox version. You could try changing them. but if this solves your problem, here you go. stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.