我会不惜一切代价避免使用这样的方法,因为它会减慢测试速度,但是我遇到了我没有其他选择的情况。
public void Wait(double delay, double interval){ // Causes the WebDriver to wait for at least a fixed delay var now = DateTime.Now; var wait = new WebDriverWait(myWebDriver, TimeSpan.FromMilliseconds(delay)); wait.PollingInterval = TimeSpan.FromMilliseconds(interval); wait.Until(wd=> (DateTime.Now - now) - TimeSpan.FromMilliseconds(delay) > TimeSpan.Zero);}
总是最好以某种方式观察DOM,例如:
public void Wait(Func<IWebDriver, bool> condition, double delay){ var ignoredExceptions = new List<Type>() { typeof(StaleElementReferenceException) }; var wait = new WebDriverWait(myWebDriver, TimeSpan.FromMilliseconds(delay))); wait.IgnoreExceptionTypes(ignoredExceptions.ToArray()); wait.Until(condition);}public void SelectionIsDoneDisplayingThings(){ Wait(driver => driver.FindElements(By.ClassName("selection")).All(x => x.Displayed), 250);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)