C#Selenium'ExpectedConditions已过时' [英] C# Selenium 'ExpectedConditions is obsolete'

查看:159
本文介绍了C#Selenium'ExpectedConditions已过时'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用ExpectedConditions显式等待某个元素变得可见时,Visual Studio警告我该元素现在已过时并将很快从Selenium中删除。

When trying to explicitly wait for an element to become visible using ExpectedConditions, Visual Studio warns me that it is now obsolete and will be removed from Selenium soon.

实现相同结果的当前/新方法是什么?

What is the current/new method to achieve the same result?

var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("content-section")));


推荐答案

我解决了自己的问题,想提供答案对于其他想知道如何使用最新版本的Selenium来解决此问题的人。

I solved my own question and wanted to provide the answer for anyone else wondering how to resolve this with the latest version of Selenium.

使用nuget,搜索DotNetSeleniumExtras.WaitHelpers,将该命名空间导入您的类。现在您可以执行以下操作:

Using nuget, search for DotNetSeleniumExtras.WaitHelpers, import that namespace into your class. Now you can do this:

var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("content-section")));

IDE中的警告将消失。

And the warning in the IDE will be gone.

这篇关于C#Selenium'ExpectedConditions已过时'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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