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
-
Possible duplicate of Dropdown selection automation using seleniumSers– Sers2019年02月21日 06:56:45 +00:00Commented 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/…Ukrainis– Ukrainis2019年02月21日 07:24:19 +00:00Commented 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!RuntimeError– RuntimeError2019年02月21日 10:39:59 +00:00Commented Feb 21, 2019 at 10:39
2 Answers 2
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
- Click the drop down first.
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..
2 Comments
var
and FindElement
=> an Java syntax
?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: ....