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,577
  • 10
  • 44
  • 82
  • Possible duplicate of [Dropdown selection automation using selenium](https://stackoverflow.com/questions/15900428/dropdown-selection-automation-using-selenium) – Sers Feb 21 '19 at 06:56
  • Seems, it is not usual drop-down. Please watch this question (I wrote there an answer, which you can try): https://stackoverflow.com/questions/53627449/how-to-select-particular-location-from-the-drop-down-list-which-is-initiated-dyn/53627717#53627717 – Ukrainis Feb 21 '19 at 07: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 Feb 21 '19 at 10:39

2 Answers2

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..

akshay patil
  • 670
  • 7
  • 20
  • `var` and `FindElement` => `an Java syntax` ? – undetected Selenium Feb 21 '19 at 07:10
  • 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) – RuntimeError Feb 21 '19 at 09:24
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: ....