public void clickWhenReady(By locator, int timeout) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); WebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(locator)); element.Click(); }
public WebElement WaitUntilElementExists(By lookupBy, int timeout = 10) { try { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); return(wait.Until(ExpectedConditions.ElementExists(lookupBy))); } catch (NoSuchElementException ex) { System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg; ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg); // Assert.Fail(lookupBy + " is not visible for " + timeout + " seconds." + " with message :" + ex.Message); throw new Exception(lookupBy + " is not visible for " + timeout + " seconds." + " with message :" + ex.Message); } }
public bool waitForInVisibilityOfElement(By by, string locator) { bool flag = false; TimeSpan time = new TimeSpan(30); WebDriverWait wait = new WebDriverWait(driver, time); try { wait.Until(ExpectedConditions.InvisibilityOfElementLocated(by)); flag = true; return(flag); } catch (Exception) { return(flag); } }
public bool waitForVisibilityOfElementUntillTimeout(By lookupBy, double timeout) { bool bln = false; WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); try { WebElement ele = wait.Until(ExpectedConditions.ElementIsVisible(lookupBy));//sunil bln = true; } catch (Exception ex) { System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg; ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg); Assert.Fail(lookupBy + " is not visible for " + timeout + " seconds." + " with message :" + ex.Message); throw new Exception(ex.Message); } return(bln); }
internal IWebElement waitForElementIsPresent(By lookupBy, int maxWaitTime = 60) { IWebElement element = null; try { element = new WebDriverWait(driver, TimeSpan.FromSeconds(maxWaitTime)).Until(ExpectedConditions.ElementExists(lookupBy)); } catch (Exception ex) { throw new Exception(ex.Message); } if (element != null) { try { string script = String.Format(@"arguments[0].style.cssText = ""border-width: 4px; border-style: solid; border-color: {0}"";", "orange"); JavascriptExecutor jsExecutor = (JavascriptExecutor)driver; jsExecutor.ExecuteScript(script, new object[] { element }); jsExecutor.ExecuteScript(String.Format(@"$(arguments[0].scrollIntoView(true));"), new object[] { element }); } catch { } } return(element); }
public void waitUntilTextPresents(By by, string text) { wait.Until(ExpectedConditions.TextToBePresentInElementLocated(by, text)); }