**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
-
Your code looks fine for me, make sure you are using correct id of dropdown. Do you getting any error?Helping Hands– Helping Hands2014年12月23日 09:23:23 +00:00Commented Dec 23, 2014 at 9:23
-
are you using webdriverjs?saifur– saifur2014年12月23日 13:45:25 +00:00Commented Dec 23, 2014 at 13:45
-
I would like to see the html of the pagesaifur– saifur2014年12月23日 14:14:39 +00:00Commented 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– Uday Reddy2014年12月23日 14:16:35 +00:00Commented Dec 23, 2014 at 14:16
5 Answers 5
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...
-
I guess you meant to write
Equals
notEquials
saifur– saifur2014年12月23日 13:43:59 +00:00Commented Dec 23, 2014 at 13:43
There are two problems
- Looks like your search option is wrong. So better to use xpath for that.
- You can just sendkeys to dropdown like in example below
Example:
client.findElement({ xpath: '//*[@id="form-tab-1"]/div/div[1]/select' }).sendKeys(Mr.);
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);
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.
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
-
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– ECiurleo2015年11月24日 15:53:38 +00:00Commented Nov 24, 2015 at 15:53