public static void WaitForElement(this RemoteWebDriver driver, By by) { var attempts = WaitTimes; while (attempts > 0) { try { ExecuteWithLogging(() => FluentWait.Create(driver) .WithTimeout(WaitTimeout) .WithPollingInterval(PollingInterval) .Until(WebDriverWaits.VisibilityOfAllElementsLocatedBy(by)), by); return; } // System.InvalidOperationException : Error determining if element is displayed (UnexpectedJavaScriptError) catch (InvalidOperationException e) { Console.WriteLine("Following Exception is occured in the WaitForElement method: {0}", e.Message); } // System.InvalidOperationException :The xpath expression './/option[contains(text(),'xxx')]' cannot be evaluated or does notresult in a WebElement catch (InvalidSelectorException e) { Console.WriteLine("Following Exception is occured in the WaitForElement method: {0}", e.Message); } catch (Exception e) { Console.WriteLine($"Error waiting element by '{by}' : {e.Message}"); throw; } finally { attempts--; } } }
// Sample usage // Driver.WaitWhileControlIsNotDisplayed<ClaimListPage>(() => claimListPage.CreateClaimButton); // OR JUST // Driver.WaitWhileControlIsNotDisplayed<ClaimListPage>(() => NowHere<ClaimListPage>().CreateClaimButton); public static void WaitWhileControlIsNotClicable <T>(this RemoteWebDriver driver, Expression <Func <IWebElement> > elementGetter) { var propertyName = ((MemberExpression)elementGetter.Body).Member.Name; var by = GetByFor <T>(propertyName); WebDriverWait wait = new WebDriverWait(driver, WaitTimeout); wait.Until(WebDriverWaits.ElementToBeClickable(by)); }
private static void WaitForLoading(this RemoteWebDriver driver, By @by) { WebDriverWait wait = new WebDriverWait(driver, WaitTimeout); wait.Until(WebDriverWaits.InvisibilityOfElementLocated(by)); }
public static void WaitWhileControlIsNotDisplayed(this RemoteWebDriver driver, By by) { WebDriverWait wait = new WebDriverWait(driver, WaitTimeout); wait.Until(WebDriverWaits.VisibilityOfAllElementsLocatedBy(by)); }