Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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);
        }