This is how the HTML looks like.
<select name="ctl00$bodyContent$ddl_Territory" onchange="javascript:setTimeout('__doPostBack(\'ctl00$bodyContent$ddl_Territory\',\'\')', 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..
List<WebElement> optionList = territory.getOptions();? Thankstry { Thread.sleep(10000); }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.