c# - 询问预期条件
问题描述
public static IWebElement WaitGetElement(IWebDriver driver, By by, int timeoutInSeconds, bool checkIsVisible = false)
{
WebDriverWait webDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds((double)timeoutInSeconds));
IWebElement result;
try
{
if (checkIsVisible)
{
result = webDriverWait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(by));
}
else
{
result = webDriverWait.Until<IWebElement>(ExpectedConditions.ElementExists(by));
}
}
catch (NoSuchElementException)
{
result = null;
}
catch (WebDriverTimeoutException)
{
result = null;
}
catch (TimeoutException)
{
result = null;
}
return result;
}
这是我的代码。它给了我错误:当前上下文中不存在名称“ExpectedConditions”。你能帮助我吗 。
解决方案
我认为您缺少这个特殊的 Nuget 包“SeleniumExtras.WaitHelpers.ExpectedConditions” https://www.nuget.org/packages/DotNetSeleniumExtras.WaitHelpers/3.11.0
您可以从 nuget 库或提供的链接下载它。稍后,正如一些评论告诉您必须在代码中添加“使用”。
我希望这有帮助
推荐阅读
- angular - 从电子邮件 Angular 6 中检索令牌
- kotlin - runBlocking 中的 deferred.await() 抛出的异常即使在被捕获后也被视为未处理
- javascript - 我怎样才能让我的测验只能通过键盘使用?
- python - Python Turtle 图形框不显示
- sql - 为表中的每个组选择第二个最新记录
- python - 使用 Sympy 的多变量梯度下降
- python - Google CLoud SQL 上 Python 的 sqlalchemy
- java - 通过 mongo-java-driver Java API 设置 Mongodb 连接池选项
- java - 在 Java 中从 HTTPS 下载
- php - 我可以使用 AWS 获取有关 Amazon.com 零售产品的产品描述吗?