예제 #1
0
        public void clickWhenReady(By locator, int timeout)
        {
            WebDriverWait wait    = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
            WebElement    element = wait.Until(ExpectedConditions.ElementToBeClickable(locator));

            element.Click();
        }
예제 #2
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);
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
        }
예제 #5
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);
        }
예제 #6
0
 public void waitUntilTextPresents(By by, string text)
 {
     wait.Until(ExpectedConditions.TextToBePresentInElementLocated(by, text));
 }