类型或命名空间名称 'IWebDriver'在 Visual Studio 2017 上通过 Selenium 执行 Nunit 测试时找不到错误 [英] The type or namespace name 'IWebDriver' could not be found error while executing Nunit test through Selenium on Visual Studio 2017

查看:53
本文介绍了类型或命名空间名称 'IWebDriver'在 Visual Studio 2017 上通过 Selenium 执行 Nunit 测试时找不到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C# 在 Mac 上使用 selenium 创建一些测试用例.我使用的 IDE 是 Visual Studio 2017.我安装了以下软件包,selenium web 驱动程序,selenium 支持,selenium firefox web 驱动程序.我的问题是如何成功使用 selenium 为使用 C# 的网站创建测试用例.每当我尝试运行测试用例时,都会弹出以下错误;

/Users/andrew/Projects/test/test/Test.cs(23,23): 错误 CS0234: 命名空间OpenQA.Selenium"中不存在类型或命名空间名称Firefox"(是你错过了一个程序集参考?)(CS0234)(测试)

/Users/andrew/Projects/test/test/Test.cs(9,9):错误 CS0246:找不到类型或命名空间名称IWebDriver"(您是否缺少 using 指令或装配参考?)(CS0246)(测试)

代码试用:

使用NUnit.Framework;使用系统;使用 OpenQA.Selenium;使用 OpenQA.Selenium.Firefox;命名空间测试{[测试夹具()]公开课测试{IWebDriver driverOne = new FirefoxDriver();[测试()]公共无效测试用例(){driverOne.Navigate().GoToUrl("http://google.com/");}}}

解决方案

参考之前的一些帖子,如果您正在通过诸如 Selenium-WebDriver 之类的框架使用 Selenium-WebDriverstrong>Visual Studio 2017nunittestadapterNUnit.Framework, VS 2017 使用 NuGet 管理器有时可能会出现安装/配置问题.

示例:SelectElement 类

根据文档

解决方案

卸载 &重新安装 Selenium.Webdriver 和 Selenium.Support 包,肯定会解决问题.

参考

您可以在

中找到相关讨论

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

这篇关于类型或命名空间名称 'IWebDriver'在 Visual Studio 2017 上通过 Selenium 执行 Nunit 测试时找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆