我试图等到一个元素出现后再继续,但是用我目前正在使用的方法,它的抛出元素不存在,甚至在超时结束之前。
示例用法:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
private static WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(30)); // inside parent class (not method)
//public static void Method1()
wait.Until(driver => driver.FindElement(By.CssSelector("[foo=bar]")));它应该等待30秒或直到元素出现,但它立即抛出元素没有找到异常.
发布于 2019-07-03 08:08:25
尝试一般使用ExpectedConditions类,特别是使用ElementExists()函数,建议的代码:
https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_Support_UI_ExpectedConditions_ElementExists.htm示例代码:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.CssSelector("[foo=bar]")));示例输出:

更多信息:
https://stackoverflow.com/questions/56862294
复制相似问题