在OpenQA.Selenium(C#)中找不到WebDriverWait类

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

 

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

例如here

 

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

here

 

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

WebDriverWait来自OpenQA.Selenium.Support.UI命名空间,并附有一个名为Selenium WebDriver支持类的单独包

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

 

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

即使我包括硒参考通过

 

using OpenQA.Selenium;

当查找documentation for WebDriverWait时,您会发现应该有一个命名空间

 

OpenQA.Selenium.Support.UI

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

为什么会发生这种情况?在哪里可以找到WebDriverWait类?

 
幸运的是,我有时也会将评论读到答案中,所以我在排名最高的评论 here中偶然发现了这个解决方案:

 

 

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中,这意味着您需要安装TWO软件包:

> NuGet包“Selenium.WebDriver”,而且
> NuGet包“Selenium.Support

来自Java与Maven,这不是微不足道的(至少对我来说),因为到现在为止,我只需要包含一个只有一个依赖关系来得到这样的“所有好东西”:

 

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

*发布这个问题包括答案,因为花费我太多的时间和运气来绊倒答案.

posted @ 2020-10-13 09:27  honeys  阅读(823)  评论(0编辑  收藏  举报