Selectingf rom dropdown list

Answered

Pls, I need help to select from dropdown list. I was able to code, see the options but unable to click the option desired. Using Java for this.  Below is the code I use..

//Selecting from Dropdown option- Stored Address


  WebElement addressSelectorDiv = driver.findElement (By.className("selectbox")); WebElement addressSelectorDropdown = addressSelectorDiv.findElement(By.tagName("select")); addressSelectorDropdown.click(); WebElement element = null; Select se=new Select(addressSelectorDropdown); for(WebElement option : se.getOptions()) { System.out.println(option.getText()); if(option.getText().isEmpty()) { System.out.println("OPTION TEXT IS EMPTY"); } } se.selectByVisibleText("240 Government Rd Go…");  //section not working se.getAllSelectedOptions().get(0).click();//section not working

jbfannie Train Asked on November 28, 2014 in Selenium WebDriver.

Please tell us the exception you are getting on this, is it no such element exception or the stale element exception.
If the option.getText() method is working, the rest should also work.
Please set the thread.sleep () for 5 sec after “addressSelectorDropdown.click();” and check if the drop down is also displayed as open list for 5 secs. If it gets closed after click then this is the issue that selenium is not able to click on the list elements, as it is closed.

on November 29, 2014.

Hi Ayo, Is that resolve?

on December 1, 2014.

Thanks. The list is open but the click does not work!

on December 1, 2014.

It can be a browser problem as well, please try with another browser. Try clicking with different ways, like mouse hovering the first value of the drop down and then click, click with build().perform(), or double click. But please do let us know the exception type.

on December 2, 2014.
Add Comment
1 Answer(s)
Best answer

Hi,

Please try .sendKeys(Keys.ENTER)

Regards,
Lakshay Sharma

xLov3rDns Professor Answered on December 2, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.