/// <summary> /// Waits the until element is no longer found. /// </summary> /// <example>Sample code to check page title: <code> /// this.Driver.WaitUntilElementIsNoLongerFound(dissapearingInfo, BaseConfiguration.ShortTimeout); /// </code></example> /// <param name="webDriver">The web driver.</param> /// <param name="locator">The locator.</param> /// <param name="timeout">The timeout.</param> public static void WaitUntilElementIsNoLongerFound(this IWebDriver webDriver, ElementLocator locator, double timeout) { var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeout)); wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException), typeof(NoSuchElementException)); wait.Until(driver => webDriver.GetElements(locator).Count == 0); }
private static ReadOnlyCollection <IWebElement> GetElements(this IWebDriver webDriver, By by, int retry) { try { return(webDriver.FindElements(by)); } catch (WebDriverException) { if (retry < WebDriverRetryLimit) { return(webDriver.GetElements(by, ++retry)); } throw; } }
private IWebElement GetElement(IWebDriver driver, CommandDesc command, CommandResult result) { var timeout = GetTimeout(command); var elements = driver.GetElements(command.Selector, timeout); var count = elements.Count(); if (count == 0) { result.HasError = true; result.Comments = "Element not found."; } else if (count > 1) { result.HasWarning = true; result.Comments = "More than one element found"; } return elements.FirstOrDefault(); }
public static bool AreElementsVisibleWithSoftAssertion(this IWebDriver webDriver, DriverContext driverContext, ElementLocator locator, string name) { try { var webElementLocator = webDriver.GetElements(locator); ReadOnlyCollection <IWebElement> collection = new ReadOnlyCollection <IWebElement>(webElementLocator); var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(BaseConfiguration.MediumTimeout)); #pragma warning disable CS0618 // Type or member is obsolete wait.Until(condition: ExpectedConditions.VisibilityOfAllElementsLocatedBy(collection)); #pragma warning restore CS0618 // Type or member is obsolete DriverContext.ExtentStepTest.Log(LogStatus.Pass, "To verify " + name + " are visible", name + " are visible successfully"); Logger.Info(name + " are displayed/Enabled successfully"); return(true); } catch (Exception e) { driverContext.VerifyMessages.Add(new ErrorDetail(null, DateTime.Now, e)); Logger.Error("An exception occured while waiting for the elements to become visible " + e.ToString()); DriverContext.ExtentStepTest.Log(LogStatus.Fail, "To verify " + name + " are visible with in provided time " + BaseConfiguration.ShortTimeout, "An exception occurred waiting for " + name + " to become visible"); Logger.Error(CultureInfo.CurrentCulture, "<VERIFY FAILS>\n{0}\n</VERIFY FAILS>", e); return(false); } }
public static ReadOnlyCollection <IWebElement> GetElements(this IWebDriver webDriver, By by) { return(webDriver.GetElements(by, 0)); }