问题描述
我想编写一个 Selenium UI 自动化,导航到特定的 URL 并等待页面呈现。
_driver.Navigate().GoToUrl("/"); //initial load
...
_driver.Navigate().GoToUrl("/counter"); //navigate async
var wait = new webdriverwait(_driver,TimeSpan.FromSeconds(3));
wait.Until(d => d.FindElementsByCssSelector(...).Count == 1)
解决方法
您可以使用其他 ExpectedConditions,例如 ElementIsVisible
() 或 ElementToBeClickable
()
new WebDriverWait(driver,TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("your selector")));
或
new WebDriverWait(driver,TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector("your selector")));