/// <summary> /// Finds and waits for an element that meets specified conditions at specified time. /// </summary> /// <typeparam name="T">IWebComponent like ICheckbox, ISelect, etc.</typeparam> /// <param name="searchContext">The search context.</param> /// <param name="locator">The locator.</param> /// <param name="timeout">Specified time to wait.</param> /// <param name="condition">The condition to be met.</param> /// <param name="customMessage">Custom message to be displayed when there is no possible to get element</param> /// <returns> /// Located and displayed element /// </returns> /// <example>How to specify element type to get additional actions for it and specify time and condition to find this element: <code> /// var checkbox = this.Driver.GetElement<Checkbox>(this.stackOverFlowCheckbox, timeout, e => e.Displayed); /// checkbox.TickCheckbox(); /// </code></example> public static T GetElement <T>(this ISearchContext searchContext, ElementLocator locator, double timeout, Func <IWebElement, bool> condition, [Optional] string customMessage) where T : class, IWebElement { IWebElement webElemement = searchContext.GetElement(locator, timeout, condition, customMessage); return(webElemement.As <T>()); }
/// <summary> /// Finds and waits for an element that is visible and displayed for long timeout. /// </summary> /// <typeparam name="T">IWebComponent like ICheckbox, ISelect, etc.</typeparam> /// <param name="searchContext">The search context.</param> /// <param name="locator">The locator.</param> /// <param name="customMessage">Custom message to be displayed when there is no possible to get element</param> /// <returns> /// Located and displayed element /// </returns> /// <example>How to specify element type to get additional actions for it: <code> /// var checkbox = this.Driver.GetElement<Checkbox>(this.stackOverFlowCheckbox); /// checkbox.TickCheckbox(); /// </code></example> public static T GetElement <T>(this ISearchContext searchContext, ElementLocator locator, [Optional] string customMessage) where T : class, IWebElement { IWebElement webElemement = searchContext.GetElement(locator, customMessage); return(webElemement.As <T>()); }
/// <summary> /// Finds and waits for an element that is visible and displayed at specified time. /// </summary> /// <typeparam name="T">IWebComponent like ICheckbox, ISelect, etc.</typeparam> /// <param name="searchContext">The search context.</param> /// <param name="locator">The locator.</param> /// <param name="timeout">Specified time to wait.</param> /// <returns> /// Located and displayed element /// </returns> /// <example>How to specify element type to get additional actions for it: <code> /// var checkbox = this.Driver.GetElement<Checkbox>(this.stackOverFlowCheckbox, timeout); /// checkbox.TickCheckbox(); /// </code></example> public static T GetElement <T>(this ISearchContext searchContext, ElementLocator locator, double timeout) where T : class, IWebElement { IWebElement webElemement = searchContext.GetElement(locator, timeout); return(webElemement.As <T>()); }
public static T WaitUntilFound <T>(this IWebDriver driver, By find, ISearchContext inContext, TimeSpan timeout = default(TimeSpan)) where T : WebElement, new() { if (timeout == default(TimeSpan)) { timeout = GlobalConfiguration.Configuration.WaitTimeout; } var wait = new WebDriverWait(driver, timeout); IWebElement element = wait.Until(dr => inContext.FindElement(find)); return(element.As <T>()); }
public Screenshot GetScreenshot() => Execute(() => element.As <ITakesScreenshot>().GetScreenshot());