/// <summary> /// Finds and waits for an element that meets specified conditions at specified time. /// </summary> /// <param name="element">The element.</param> /// <param name="locator">The locator.</param> /// <param name="timeout">The timeout.</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> /// Return found element /// </returns> /// <example>How to use it: <code> /// this.Driver.GetElement(this.loginButton, timeout, e => e.Displayed); /// </code></example> public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, Func <IWebElement, bool> condition, [Optional] string customMessage) { var driver = element.ToDriver(); if (DriversCustomSettings.IsDriverSynchronizationWithAngular(driver)) { driver.WaitForAngular(); } var by = locator.ToBy(); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)) { Message = customMessage }; wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException)); wait.Until( drv => { var ele = element.FindElement(@by); return(condition(ele)); }); return(element.FindElement(@by)); }
public static void WaitForElementVisibility(IWebDriver driver, ElementLocator locator) { ISearchContext element; var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(BaseConfiguration.ShortTimeout)); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(locator.ToBy())); }
public static void SendKeys(this IWebDriver driver, ElementLocator locator, string text) { if (!string.IsNullOrEmpty(text)) { var el = new WebDriverWait(driver, TimeSpan.FromSeconds(Wait)).Until( ExpectedConditions.ElementToBeClickable(driver.FindElement(locator.ToBy(locator)))); //ugly hack becaue of unknown error: cannot focus element in chromedriver //TODO replace by sendKeys when bug is fixed new Actions(driver).MoveToElement(el).Click().SendKeys(text).Build().Perform(); } }
public static bool IsElementDisplayed(this IWebDriver driver, ElementLocator locator) { try { return(new WebDriverWait(driver, TimeSpan.FromSeconds(Wait)) .Until(ExpectedConditions.ElementIsVisible(locator.ToBy(locator))) .Displayed); } catch (WebDriverTimeoutException) { return(false); } }
public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, Func <IWebElement, bool> condition) { var driver = ToDriver(element); var by = locator.ToBy(); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException)); wait.Until(x => { var ele = element.FindElement(by); return(condition(ele)); }); return(element.FindElement(by)); }
/// <summary> /// Finds and waits for an element that meets specified conditions at specified time, recheck condition at specific time interval. /// </summary> /// <param name="element">The element.</param> /// <param name="locator">The locator.</param> /// <param name="timeout">The timeout.</param> /// <param name="timeInterval">The value indicating how often to check for the condition to be true..</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> /// Return found element /// </returns> /// <example>How to use it: <code> /// this.Driver.GetElement(this.loginButton, timeout, timeInterval, e => e.Displayed & e.Enabled); /// </code></example> public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, double timeInterval, Func <IWebElement, bool> condition, [Optional] string customMessage) { var by = locator.ToBy(); var wait = new WebDriverWait(new SystemClock(), element.ToDriver(), TimeSpan.FromSeconds(timeout), TimeSpan.FromSeconds(timeInterval)) { Message = customMessage }; wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException)); wait.Until( drv => { var ele = element.FindElement(@by); return(condition(ele)); }); return(element.FindElement(@by)); }
/// <summary> /// Finds elements that meet specified conditions. /// </summary> /// <param name="element">The element.</param> /// <param name="locator">The locator.</param> /// <param name="condition">Condition to be fulfilled by elements</param> /// <returns> /// Return all found elements for specified conditions /// </returns> /// <example>How to find disabled elements : <code> /// var checkboxes = this.Driver.GetElements(this.stackOverFlowCheckbox, e => e.Enabled == false); /// </code></example> public static IList <IWebElement> GetElements(this ISearchContext element, ElementLocator locator, Func <IWebElement, bool> condition) { return(element.FindElements(locator.ToBy()).Where(condition).ToList()); }
public static IList <IWebElement> GetElements(this ISearchContext element, ElementLocator locator) { return(element.FindElements(locator.ToBy()).Where(e => e.Displayed && e.Enabled).ToList()); }
public static void Click(this IWebDriver driver, ElementLocator locator) { new WebDriverWait(driver, TimeSpan.FromSeconds(Wait)).Until( ExpectedConditions.ElementToBeClickable(driver.FindElement(locator.ToBy(locator)))).Click(); }
public static ReadOnlyCollection <IWebElement> FindElements(this IWebDriver driver, ElementLocator locator, params object[] parameters) { locator = locator.Format(parameters); new WebDriverWait(driver, TimeSpan.FromSeconds(Wait)).Until(drv => driver.FindElements(locator.ToBy(locator)).Count > 0); return(driver.FindElements(locator.ToBy(locator))); }
public static string GetText(this IWebDriver driver, ElementLocator locator) { return(new WebDriverWait(driver, TimeSpan.FromSeconds(Wait)).Until( ExpectedConditions.ElementIsVisible(locator.ToBy(locator))).Text); }