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(“s2id_QuickEnquiryForm_salutation”)));

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,

DropDown means we select value from the dropdown, and every dropdown will be having “select” tag. You are getting  “select” but was “div”” error because, the tag is “div” instead “select”.

And Dropdown and serach/text fields are different. Your object is text field but NOT dropdown field.

Ex: See below code and you can see the select tag from this use can select the dropdown value. URL:

  1. <select id=”month class=”_5dba name=”birthday_month>
  2. <option selected=”1 value=”0>Month</option>
    <option value=”1>Jan</option>
    <option value=”2>Feb</option>
    <option value=”3>Mar</option>
    <option value=”4>Apr</option>
    <option value=”5>May</option>
    <option value=”6>Jun</option>
    <option value=”7>Jul</option>
    <option value=”8>Aug</option>
    <option value=”9>Sep</option>
    <option value=”10>Oct</option>
    <option value=”11>Nov</option>
    <option value=”12>Dec</option>
  3. </select>

Hope you got the answer.

Vice Professor Answered on December 30, 2014.

Hi Sachin,

Thanks for your reply..I have already checked Facebook home page  they are using  Select.  but the issue is  we have  div  tag instead of Select.

in our over all  application we are using div only to select values from drop down.

if you have any idea regarding  how to work with div, can you please suggest valuable thoughts. if you want i will share my Source code page also.

Thanks in Advance.

Thanks & Regards,
Uday Reddy.S

on December 30, 2014.

Hi Uday,

As per your question and error message I gave my suggestions.

Note: Please see your code and error message.

As per your Comment I came to know what is the issue is 🙂 .

Please give me sample url please let me try 🙂 .

And Uday, see below question and it is related or similar i think.

on December 31, 2014.
Add Comment

Your Answer

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