Selenium C# WebDriver:等到元素出现 [英] Selenium C# WebDriver: Wait until element is present

查看:38
本文介绍了Selenium C# WebDriver:等到元素出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确保在 webdriver 开始执行某些操作之前存在一个元素.

我正在努力让这样的事情发挥作用:

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

我主要是在努力如何设置匿名函数...

解决方案

或者你可以使用隐式等待:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

<块引用>

隐式等待是告诉 WebDriver 轮询某个特定的 DOM尝试查找一个或多个元素(如果它们是)的时间不是立即可用.默认设置为 0.一旦设置,为 WebDriver 对象实例的生命周期设置隐式等待.

I want to make sure that an element is present before the webdriver starts doing stuff.

I'm trying to get something like this to work:

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

I'm mainly struggling how to setup up the anonymous function...

解决方案

Alternatively you can use an implicit wait:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

这篇关于Selenium C# WebDriver:等到元素出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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