[英]Cannot find WebDriverWait class in OpenQA.Selenium (C#)
(Migrating from Java-Selenium to C#-Selenium) (从 Java-Selenium 迁移到 C#-Selenium)
When searching for explicit waits with Selenium and C# I find several posts with code that looks similar to the Java-Counterpart:在使用 Selenium 和 C# 搜索显式等待时,我发现有几篇文章的代码看起来类似于 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 are from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes WebDriverWait 来自 OpenQA.Selenium.Support.UI 命名空间,并在一个名为 Selenium WebDriver Support Classes 的单独包中
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:当我尝试在 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?)
找不到类型或命名空间名称“WebDriverWait”(您是否缺少 using 指令或程序集引用?)
Even though I am including the Selenium reference via即使我通过
using OpenQA.Selenium;
When looking up the documentation for WebDriverWait you will find, that there should be a namespace called在查找WebDriverWait的文档时,您会发现,应该有一个名为
OpenQA.Selenium.Support.UI
OpenQA.Selenium.Support.UI
But I cannot access it via "using" in my code.但是我无法通过代码中的“使用”访问它。
Why does this happen?为什么会发生这种情况? Where can I find the WebDriverWait class?
在哪里可以找到 WebDriverWait 类?
Luckily I sometimes read the comments to answers as well, so I stumbled across the solution within the highest ranked comment here :幸运的是,我有时也会阅读答案的评论,所以我在此处排名最高的评论中偶然发现了解决方案:
WebDriverWait [is] from the OpenQA.Selenium.Support.UI namespace and comes in a separate package called Selenium WebDriver Support Classes on NuGet
WebDriverWait [是] 来自 OpenQA.Selenium.Support.UI 命名空间,并在 NuGet 上名为 Selenium WebDriver Support Classes的单独包中
Thanks @Ved!谢谢@Ved!
In Visual Studio this means, that you need to install TWO packages:在 Visual Studio 中,这意味着您需要安装两个包:
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:来自 Java 和 Maven,这不是微不足道的(至少对我来说 ;-),因为直到现在我只需要包含一个并且只有一个依赖项来获得“所有好东西”,如下所示:
<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. * 将此作为一个包含答案的问题发布,因为我花了太多时间和运气来绊倒答案。
Have you tried adding?你试过添加吗?
using OpenQA.Selenium.Support.UI;
That should be all you need.这应该就是你所需要的。 Depending on your IDE, it likely (?) will have a helper that will find and add missing references.
根据您的 IDE,它可能 (?) 会有一个帮助程序来查找和添加缺失的引用。 I use Visual Studio.
我使用 Visual Studio。 I just type what I know should be there.
我只是输入我知道应该在那里的内容。 When the IDE puts red squiggles on WebDriverWait, I hover over it and it shows a tooltip that says I'm missing a reference and I click on the link, Show potential fixes.
当 IDE 在 WebDriverWait 上放置红色波浪线时,我将鼠标悬停在它上面,它会显示一个工具提示,指出我缺少参考,然后我单击链接显示潜在的修复。 In the new tooltip it shows several options, usually the first of which is to add the
using
statement.在新的工具提示中,它显示了几个选项,通常第一个是添加
using
语句。 I click that one and the red squiggles go away.我点击那个,红色的波浪线消失了。
I really like Visual Studio but I've been using Eclipse for the last 9 months or so and I prefer the way Eclipse handles this.我真的很喜欢 Visual Studio,但在过去 9 个月左右的时间里我一直在使用 Eclipse,我更喜欢 Eclipse 处理这个问题的方式。 I think it's more intuitive... but that's just me.
我认为它更直观......但这只是我。
EDIT编辑
Just wanted to make clear for future readers... I don't use NuGet.只是想为未来的读者说清楚……我不使用 NuGet。 I just download the Selenium .Net package and drop the 4 DLLs in/near my project and then add references to all 4 of them to my Visual Studio project.
我只是下载 Selenium .Net 包并将 4 个 DLL 放在我的项目中/附近,然后将所有 4 个 DLL 的引用添加到我的 Visual Studio 项目中。 Once I do that and use the instructions above, it works for me.
一旦我这样做并使用上面的说明,它就对我有用。
WebDriverWait is not available in OpenQA.selenium. WebDriverWait 在 OpenQA.selenium 中不可用。 Its Available SeleniumExtras.WaitHelpers
其可用的 SeleniumExtras.WaitHelpers
using OpenQA.Selenium;
using SeleniumExtras.WaitHelpers;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("Test")));
Selenium.WebDriver.WaitExtentions。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.