在OpenQA.Selenium(C#)中找不到WebDriverWait类 [英] Cannot find WebDriverWait class in OpenQA.Selenium (C#)

查看:275
本文介绍了在OpenQA.Selenium(C#)中找不到WebDriverWait类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(从Java-Selenium迁移到C#-Selenium)

(Migrating from Java-Selenium to C#-Selenium)

在使用Selenium和C#搜索显式等待时,我发现一些帖子的代码看起来类似于Java-Counterpart:

When searching for explicit waits with Selenium and C# I find several posts with code that looks similar to the Java-Counterpart:

例如此处:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5));
wait.Until(By.Id("login"));

此处:

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("locator")));

WebDriverWait来自OpenQA.Selenium.Support.UI命名空间,并且位于一个单独的名为Selenium WebDriver支持类的程序包中

WebDriverWait are from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes

但是:
当我尝试在Visual Studio中自己编写代码(通过NuGet获取Selenium程序包)时,在代码中使用WebDriverWait将提示消息:

BUT:
When I try to code this myself in Visual Studio (getting Selenium package via NuGet), using WebDriverWait in my code will prompt the message:

找不到类型或名称空间名称'WebDriverWait'(您是 缺少using指令或程序集引用?)

The type or namespace name 'WebDriverWait' could not be found (are you missing a using directive or an assembly reference?)

即使我通过添加了硒参考

Even though I am including the Selenium reference via

using OpenQA.Selenium;

查找 WebDriverWait的文档时,您会发现应该有一个名为

When looking up the documentation for WebDriverWait you will find, that there should be a namespace called

OpenQA.Selenium.Support.UI

OpenQA.Selenium.Support.UI

但是我无法通过代码中的使用"来访问它.

But I cannot access it via "using" in my code.

为什么会这样?在哪里可以找到WebDriverWait类?

推荐答案

幸运的是,有时我也会阅读答案的评论,因此我偶然在排名最高的评论

Luckily I sometimes read the comments to answers as well, so I stumbled across the solution within the highest ranked comment here:

WebDriverWait [是]来自OpenQA.Selenium.Support.UI命名空间和 名为Selenium WebDriver支持类的单独软件包中 在NuGet上

WebDriverWait [is] from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes on NuGet

感谢@Ved!

在Visual Studio中,这意味着您需要安装两个软件包:

In Visual Studio this means, that you need to install TWO packages:

  • NuGet程序包" Selenium.WebDriver ",并且
  • NuGet程序包" Selenium.Support "
  • NuGet package "Selenium.WebDriver" AND ALSO
  • NuGet package "Selenium.Support"

来自Java和Maven,这并非微不足道(至少对我而言;-),因为直到现在,我只需要包含一个并且只有一个依赖关系才能获得所有的好东西",如下所示:

Coming from Java with Maven, this is not trivial (at least to me ;-), because until now I just needed to include one and only one dependency to get "all of the good stuff" like this:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.46.0</version>
</dependency>

*这是一个包含答案的问题,因为我花了太多时间和运气才迷失了答案.

* Posted this as a question including the answer because it cost me too much time and luck to stumble over the answer.

这篇关于在OpenQA.Selenium(C#)中找不到WebDriverWait类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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