RE: How to Retrieve the values from a drop down using selenium-WebDriver?

I am using below script to retrieve specific item from drop down but it’s not working.

Select  salTitle =  new Select(driver.findElement(By.id(“s2id_QuickEnquiryForm_salutation”)));
 salTitle.selectByVisibleText(“Mr.”);

showing below Error in console “Exception in thread “main” org.openqa.selenium.suppo

RE: How to Retrieve the values from a drop down using selenium-WebDriver?

rt.ui.UnexpectedTagNameException: Element should have been “select” but was “div””

I am using selenium + javascript.can anyone here suggest a method to select an item from a dropdown menu.

please find the Below HTML,Source code for your reference!!

please find the attached image for HTML code of Specific to that field.

I welcome any input!

Thanks in advance!!

Uday Train Asked on December 29, 2014 in Selenium WebDriver.

This is a very beautifully asked question. Thanks Uday!

on December 31, 2014.
Add Comment
4 Answers

Hi Uday

If you have all drop down with div , you can simply right your own wrapper around it code would be something like below


public static boolean selectDivDropDown(WebElement element,String matchingText){

element.click();

List<WebElement> dropDownList = element.findElements(By.tagName("a"));

for(WebElement dropDown:dropDownList){

if(dropDown.getText().equalsIgnoreCase(matchingText)){

dropDown.click();

return true;

}

}

throw new IllegalArgumentException("Not able to find Element with Text:"+matchingText+"inside the WebElement:"+element.toString());

}

Please note this is just example , I have not checked the exact html and neither have tested this code , but you can take it forward from there

Supporter Answered on January 2, 2015.
Add Comment

Your Answer

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