9
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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Kevin
  • 147
  • 1
  • 1
  • 10
  • 1
    Welcome to SO. It's better to include the text of your error in the question rather than as an image. You will also need to include the relevant portion of your code. See https://stackoverflow.com/help/mcve – Nick Jul 20 '18 at 06:48
  • Kevin avoid posting the image link and share your code on the question with proper format. You can refer this link [how to ask a question](https://stackoverflow.com/help/how-to-ask) – Ashok kumar Ganesan Jul 20 '18 at 06:49
  • If you are using Visual Studio, try right-clicking on `SelectElement` and then `resolve namespace` click on correct namespace, so it will add it at the top of the file – Rafalon Jul 20 '18 at 07:05
  • @Rafalon it didn't show any namespace there. it only show this three( Generate class SelectElement in a new file, generate class SelectElement and generate nested class SelectElement) when right click – Kevin Jul 20 '18 at 07:14
  • @Kevin Show the "using" import lines on the top of your code. The issue is probably there – Shivam Mishra Jul 20 '18 at 07:17
  • using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.UI; – Kevin Jul 20 '18 at 07:19
  • Do you have any error on one of these lines? Like maybe you don't have the references included in your project? – Rafalon Jul 20 '18 at 07:22
  • @Rafalon no error the only thing is using OpenQA.Selenium.Support.UI; greyed out – Kevin Jul 20 '18 at 07:25
  • the answer from @BHOW is the only one to solve the OP. – GilShalit Jan 27 '19 at 20:50

7 Answers7

13

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;
BHOW
  • 194
  • 3
10

Referring to a few previous posts it seems if you are using frameworks like nunittestadapter, NUnit.Framework, VS 2017 using the NuGet Manager sometimes there can be issues with the installation /configuration.

SelectElement Class

As per the documentation the SelectElement Class is pretty much available within OpenQA.Selenium.Support.UI Namespace which provides a convenience method for manipulating selections of options in an HTML select element.


Inheritance Hierarchy

System.Object
    OpenQA.Selenium.Support.UI.SelectElement

Namespace: OpenQA.Selenium.Support.UI


Assembly: WebDriver.Support (in WebDriver.Support.dll) Version: 3.1.0


Syntax: public class SelectElement : IWrapsElement


Snapshot:

selectelement_class

Solution

Uninstall & reinstall the Selenium.Webdriver and Selenium.Support packages, that will surely fix the problem.

Reference

You can find a relevant discussion in Cannot find WebDriverWait class in OpenQa Selenium 3.7

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    yes your answer is correct! i reinstall the webdriver support and it is working now!. thanks – Kevin Jul 25 '18 at 02:19
2

Selenium WebDriver C# code for selecting item from Drop Down:

IWebElement selectElement = driver.FindElement(By.Id("selectFilterbyUser"));
SelectElement oSelect = new SelectElement(selectElement);

There are 3 ways to select drop down item: byText, byIndex, byValue

1.byText()

oSelect.SelectByText("Alex");

2.byIndex()

SelectAnEducation.SelectByIndex(0);

3.byValue()

SelectAnEducation.SelectByValue("Alex");

Hope this helps,

Kovacic
  • 1,473
  • 6
  • 21
2

I had the same issue due to using the pre-release version. v4.00 alpha. I installed the previous version v3.141.0 and the errors were resolved

enter image description here

  • I did the very same thing, and it didn't work with the newest version of chromedriver. It instead gave me "Could not load type 'OpenQA.Selenium.Internal.IWrapsElement'" – Erin B Jan 14 '20 at 20:11
  • It's all fun and stuff when installing newest versions until all the documentation and tutorials with SelectElement are obsolete. Much appreciated! Just what I thought about this! – idchlife Feb 09 '20 at 09:44
0

First of all, You need to install the proper package from NuGet which is Selenium.Support

Correct using statements is as:

using OpenQA.Selenium.Support.UI;

Pankaj
  • 1
  • 2
0

Starting with Selenium.WebDriver 4.0, one needs to install both Selenium.WebDriver and Selenium.Support nuget packages (same version) to avoid this issue (IWrapsElement / type load exceptions).

Cosmin Sontu
  • 1,034
  • 11
  • 16
0

In Dotnet 4.7, SelectElement is found under Selenium Support driver in Nuget Package

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 02 '22 at 10:40