1

I want to select particular value from drop-down menu but stuck at it, I can load dropdown but cant select anyone of them, here is below details

enter image description here

Here is HTML details enter image description here

enter image description here

C# code

driver.FindElement(By.ClassName("select2")).Click();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
driver.FindElement(By.Id("select2-alpaca4-container")).Click();
driver.FindElement(By.XPath("//span[@id='select2-alpaca4-container']/..//*[text()='Normal User']")).Click();

I cannot use select since it has span as it is throwing error message "Element should have been select but was span" Can someone please provide me correct code here to select any one of the value

1
  • the below solution is working are not
    – Vel Guru
    Commented Dec 25, 2018 at 6:00

1 Answer 1

1

Try the below options:

driver.findElement(By.id("select2-alpaca4-container")).click();
Thread.sleep(3000L);
driver.findElement(By.xpath(".//span[contains(text(), 'Normal User')]")).click();

OR

driver.findElement(By.id("select2-alpaca4-container")).click();  
Thread.sleep(3000L); 
driver.findElement(By.xpath(".//span[contains(@title, 'Normal User')]")).click();
2
  • tried both but returns penQA.Selenium.NoSuchElementException occurred HResult=0x80131500 Message=no such element: Unable to locate element: {"method":"xpath","selector":".//span[contains(@title, 'Normal User')]"}
    – Amol Datar
    Commented Dec 25, 2018 at 10:16
  • have you clicked on "dropdown"
    – Vel Guru
    Commented Dec 25, 2018 at 10:24

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.