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

asked Dec 23, 2014 at 9:20
4
  • Your code looks fine for me, make sure you are using correct id of dropdown. Do you getting any error? Commented Dec 23, 2014 at 9:23
  • are you using webdriverjs? Commented Dec 23, 2014 at 13:45
  • I would like to see the html of the page Commented 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. Commented 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...

answered Dec 23, 2014 at 10:45
1
  • I guess you meant to write Equals not Equials Commented 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.);
Niels van Reijmersdal
32.7k4 gold badges59 silver badges125 bronze badges
answered Feb 1, 2015 at 10:23
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);
ECiurleo
2,0431 gold badge16 silver badges45 bronze badges
answered Nov 24, 2015 at 15:45
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.

IAmMilinPatel
7,7667 gold badges44 silver badges68 bronze badges
answered Aug 5, 2016 at 9:36
-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

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered Dec 29, 2014 at 12:09
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? Commented Nov 24, 2015 at 15:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.