1

I have a Dropdown-Box which looks like this: Dropdown-Box

I need test this Dropdown-Menu and use this Code:

IWebElement classes = driver.FindElement(By.CssSelector("span#select2-ctl00_ctl00_BaseRightContent_MainRightContent_EditMachineDetails_MachineClassList-container"));
SelectElement selectClass = new SelectElement(classes);
selectClass.SelectByText(Parameters.GivenClass);

Does anybody know how to deal with this Error: Element should have been select but was span

Because the new Selenium doen't offer anymore the "Select"-Class

NarendraR
7,71811 gold badges49 silver badges89 bronze badges
asked Feb 21, 2019 at 6:49
3
  • Possible duplicate of Dropdown selection automation using selenium Commented Feb 21, 2019 at 6:56
  • Seems, it is not usual drop-down. Please watch this question (I wrote there an answer, which you can try): stackoverflow.com/questions/53627449/… Commented Feb 21, 2019 at 7:24
  • Seems like the Answers below. I tried it with By.Name but as mentioned below my Values come with in a li. Check my other Answer for Details ... Thanks for the help! Commented Feb 21, 2019 at 10:39

2 Answers 2

0

I think Select only work for the dropdown element which are present in option but if the element is present inside the div or span then Select class will not work in some cases, so suggestion is to you please use the difference way to select the element you can do one thing

  1. Click the drop down first.
  2. If the drop down values are unique then you can use this..

    driver.FindElement(By.Name("dropdownvalue")).click(); //This is an Java syntax

After this you can click the element or you can use sendKeys() for that you need the input has to preset in the source of drop down Try and let us know..

answered Feb 21, 2019 at 7:06
Sign up to request clarification or add additional context in comments.

2 Comments

var and FindElement => an Java syntax ?
Thanks for the answer, I came the solution closer. But the Problem now is that the elements are in a list and i cant locate that with By.Name (tried already to find the list element by CssSelector but ended up with an error)
0

Here you can see my Page & HTML-Content. Tried already the following things:

 IWebElement classes = driver.FindElement(By.CssSelector("span#select2-ctl00_ctl00_BaseRightContent_MainRightContent_EditMachineDetails_MachineClassList-container"));
 classes.Click();
 //IWebElement classclickelement = driver.FindElement(By.Name(registerLiebherrMachineParam.MachineClass));
 //classclickelement.Click();
 IWebElement classestextbox = driver.FindElement(By.CssSelector("input[class='select2-search__field'][role='textbox']"));
 classestextbox.SendKeys(registerLiebherrMachineParam.MachineClass); 
 IWebElement clickgivenclass = driver.FindElement(By.CssSelector($"li[class='select2-results__option select2-results__option--highlighted'][value='{registerLiebherrMachineParam.MachineClass}']"));
 clickgivenclass.Click();

This is my Error-Code: Additional information: no such element: Unable to locate element: ....

answered Feb 21, 2019 at 10:34

Comments

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.