0

I'm working on a c# selenium script where i need to select a value from the drop down list. When trying to select it , getting "Element should have been select but was span" error

I am able to get to the website, and everything is working as expected. But when trying to select the option var selectElement = new SelectElement(opt); it throws an error. I know i'm wrong somewhere, need help

  var opt = driver.FindElement(By.XPath("/html/body/div[7]/div[2]/div/div[2]/span/span/span[1]"));
var selectElement = new SelectElement(opt);
System.Threading.Thread.Sleep(12000);
selectElement.SelectByText("ABN MRI");

The HTML code for the site is

<span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">ABN RealPage</span><span unselectable="on" class="k-select"><span unselectable="on" class="k-icon k-i-arrow-s">select</span></span></span>
<input id="AvidIntegration_InstanceList" style="width: 350px; display: none;" data-role="dropdownlist">

I expect it should select the desired option but here its not working.

1 Answers1

0

The Element you are trying to select is actually a 'Span' element which you can not put in 'SelectElement' class constructor to get an object.

Rather what you can do is:

  • Click the input element right below it. (I hope that is the one which is triggering the click event)
  • See what elements are provided in the selection box.
  • Click one of them using a respective CSS selector or XPath according to your preference.