1

**enter image description here**

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

I welcome any input!

please find the Below attched Images for HTML,Source Code.enter image description here

4
  • Your code looks fine for me, make sure you are using correct id of dropdown. Do you getting any error? Dec 23, 2014 at 9:23
  • are you using webdriverjs?
    – saifur
    Dec 23, 2014 at 13:45
  • I would like to see the html of the page
    – saifur
    Dec 23, 2014 at 14:14
  • I'm not getting any error & not highlighting value in field also.if you have any better idea can you please give valuable suggetsions.
    – Uday Reddy
    Dec 23, 2014 at 14:16

5 Answers 5

1

I'm not sure how "yours" dropdown works, but for me "working solution" in similar case is:

Field.SendKeys(123)
for (j=0; ; j++)
{
if (Driver.FindElement(By.XPath("li[j] element")).GetElementText().Equals(should_to_select_value);
   {
       if (Driver.FindElement(By.XPath("li[j] element")).Click();
       break;
   }
}

Also, I'm sorry for example not in javascript...

1
  • I guess you meant to write Equals not Equials
    – saifur
    Dec 23, 2014 at 13:43
1

There are two problems

  1. Looks like your search option is wrong. So better to use xpath for that.
  2. You can just sendkeys to dropdown like in example below

Example:

client.findElement({ xpath: '//*[@id="form-tab-1"]/div/div[1]/select' }).sendKeys(Mr.);
1

try this if drop down has search functionality

driver.findelement(by.xpath("your drop down arrow button or select button path")).click
driver.findelement(by.xpath("your drop down search text box path")).sendkeys("values ");
driver.findelement(by.xpath("your drop down search text box path")).sendkeys(Keys.arrowdown, keys.enter);
0

I was getting same error but I resolved it with the below piece of code,

driver.findElement(By.xpath(".//*[@id='BirthMonth']/div")).sendKeys("June");
Thread.sleep(30000);
driver.findElement(By.xpath(".//*[@id='BirthMonth']/div")).sendKeys("July");
Thread.sleep(30000);
driver.findElement(By.xpath(".//*[@id='BirthMonth']/div")).sendKeys("August");
Thread.sleep(30000);

Finally I am able to get "August" month automatically.

-1

For selecting a drop-down value, I have one of the working solutions.take the XPath of the dropdown and edit the drop-down XPath like below

(....)/select/option[@value=' ']

' ' - indicates that enter your option to select from drop-down

Now by using this XPath use the click() method to select an option from drop-down

I hope it is useful for you.

Please mark it correct if it works for you

1
  • That doesn't really answer his scenario. Can you give more of a reasoning why you are using that method and maybe a bit of further reading so they can understand the background?
    – ECiurleo
    Nov 24, 2015 at 15:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.