简体   繁体   中英

The type or namespace name 'IWebDriver' could not be found error while executing Nunit test through Selenium on Visual Studio 2017

I am trying to create some test cases with selenium on a mac with C#. The IDE I am using is visual studio 2017. I have the following packages installed , selenium web driver, selenium support, selenium firefox web driver. My Question is how do I successfully use selenium to create test cases for website using C#. Whenever I try to run the test cases, the following errors pop up ;

/Users/andrew/Projects/test/test/Test.cs(23,23): Error CS0234: The type or namespace name 'Firefox' does not exist in the namespace 'OpenQA.Selenium' (are you missing an assembly reference?) (CS0234) (test)      

and

/Users/andrew/Projects/test/test/Test.cs(9,9): Error CS0246: The type or namespace name 'IWebDriver' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (test)

Code trial:

using NUnit.Framework;
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace test
{
    [TestFixture()]
    public class Test
    {

        IWebDriver driverOne = new FirefoxDriver();

        [Test()]
        public void TestCase()
        {
            driverOne.Navigate().GoToUrl("http://google.com/");
        }
    }
}

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

Example: 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:

选择元素类

Solution

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

Reference

You can find relevant discussions in

从 Selenium.WebDriver 4.0 开始,需要同时安装 Selenium.WebDriver 和 Selenium.Support nuget 包(相同版本)以避免此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM