// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The SFC licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. // namespace OpenQA.Selenium.Support.UI; /// /// Provides the ability to wait for an arbitrary condition during test execution. /// /// /// /// IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3)) /// IWebElement element = wait.Until(driver => driver.FindElement(By.Name("q"))); /// /// public class WebDriverWait : DefaultWait { /// /// Initializes a new instance of the class. /// /// The WebDriver instance used to wait. /// The timeout value indicating how long to wait for the condition. public WebDriverWait(IWebDriver driver, TimeSpan timeout) : this(SystemClock.Instance, driver, timeout, DefaultSleepTimeout) { } /// /// Initializes a new instance of the class. /// /// An object implementing the interface used to determine when time has passed. /// The WebDriver instance used to wait. /// The timeout value indicating how long to wait for the condition. /// A value indicating how often to check for the condition to be true. /// If or are . public WebDriverWait(IClock clock, IWebDriver driver, TimeSpan timeout, TimeSpan sleepInterval) : base(driver, clock) { this.Timeout = timeout; this.PollingInterval = sleepInterval; this.IgnoreExceptionTypes(typeof(NotFoundException)); } private static TimeSpan DefaultSleepTimeout => TimeSpan.FromMilliseconds(500); }