The type or namespace SelectElement could not be found in selenium c#

Kevin picture Kevin · Jul 20, 2018 · Viewed 16.3k times · Source
driver.FindElement(By.Id("inputUsername")).SendKeys("aca");
driver.FindElement(By.Id("inputPassword")).SendKeys("123");
driver.FindElement(By.TagName("button")).Click();

SelectElement oSelect = new SelectElement(driver.FindElement(By.Id("selectFilterbyUser")));
oSelect.selectByText("Alex");

Do anyone have solution for the problem that i had attach in the above? Try to use SelectElement but it displays:

The type or namespace `SelectElement` could not be found.

I tried to see the potential fixes, but it shows only three options which are

  • Generate class SelectElement in a new file
  • Generate class SelectElement
  • Generate nested class SelectElement

Does anyone know how to solve it?

Answer

BHOW picture BHOW · Sep 7, 2018

You need to make sure to reference the NuGet Package Selenium.Support.

I was having the same issue and then realized that I was only referencing the Selenium.WebDriver NuGet Package. After adding the Selenium.Support NuGet package, and adding the proper using statements. My SelectElement code successfully compiled.

The proper using statements

using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;