c# - 显式等待 Selenium Webdriver 获取手中的元素

标签 c# selenium

我在 C# 上使用 selenium webdriver,我正在使用页面对象模块。现在我需要一个语法来显式等待,因为我已经有了 web 元素。

[FindsBy(How = How.Id, Using = "Passwd")]
public IWebElement Password {get;set;}

[FindsBy(How = How.Id, Using = "signIn")]
public IWebElement Signin { get; set; }

我需要等到找到元素密码。

在使用这个模块之前,我使用的是:

WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time));
wait.Until(ExpectedConditions.ElementExists(by));

现在我需要使用手头的元素。

最佳答案

您应该尝试使用 ExpectedConditions.ElementToBeClickable它将接受 IWebElement 以及输入,并会等到元素可见并启用,如下所示:-

WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time));
wait.Until(ExpectedConditions.ElementToBeClickable(Password));

关于c# - 显式等待 Selenium Webdriver 获取手中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975256/

相关文章:

c# - 如何防止 System.IO.File.Open 和 FileMode.Truncate 导致文件更改

python - 如何在 Python 中使用 Selenium 访问弹出式登录表单

java - 如何限制用作工厂的 TestNG dataprovider 方法上的线程

selenium - 如何将 Selenium Webdriver 连接到现有的 Firefox/Chrome 浏览器 session ?

java - 动态创建.xlsx文件并将其用作testNg selenium框架中的数据提供者/供应商

javascript - 使用 Selenium 修改 JavaScript 变量

c# - 写入PS/2端口

c# - 无法找到请求的 .Net Framework 数据提供程序。它可能没有安装。 vs 2010 和 sql server 2008 express

c# - 无法保存对身份用户的更改?

c# - 让所有 parent 共有的 child