public static IWebElement FindElement(this IWebElement element, By by, int timeoutInSeconds)
        {
            if (timeoutInSeconds <= 0) return element.FindElement(@by);

            var wait = new DefaultWait<IWebElement>(element)
            {
                Timeout = TimeSpan.FromSeconds(timeoutInSeconds),
                PollingInterval = TimeSpan.FromMilliseconds(500.0)
            };
            wait.IgnoreExceptionTypes(new[] { typeof(NotFoundException) });
            return wait.Until(e => e.FindElement(@by));
        }
        /// <summary>
        /// Find an element, waiting until a timeout is reached if necessary.
        /// </summary>
        /// <param name="context">The search context.</param>
        /// <param name="by">Method to find elements.</param>
        /// <param name="timeout">How many seconds to wait.</param>
        /// <param name="displayed">Require the element to be displayed?</param>
        /// <returns>The found element.</returns>
        public static IWebElement FindElement(this ISearchContext context, By by, uint timeout, bool displayed = false)
        {
            var wait = new DefaultWait<ISearchContext>(context);
            wait.Timeout = TimeSpan.FromSeconds(timeout);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            return wait.Until(ctx =>
            {
                var elem = ctx.FindElement(by);
                if (displayed && !elem.Displayed)
                    return null;

                return elem;
            });
        }
        public void ElementToDisappear()
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(15);
            wait.PollingInterval = System.TimeSpan.FromSeconds(1);

            try
            {
                wait.Until(drv => isElementNotAvailableNow(drv, _locator));
            }
            catch (NoSuchElementException)
            {
            }
            catch (WebDriverTimeoutException)
            {
            }
        }
        public void ElementClassToContainValidated()
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(5);
            wait.PollingInterval = System.TimeSpan.FromMilliseconds(500);

            try
            {
                wait.Until(drv => doesElementClassContains(drv, _locator, "validated"));
            }
            catch (NoSuchElementException)
            {
            }
            catch (WebDriverTimeoutException)
            {
            }
        }
        public void BorderColorToChangeTo(string expectedColorHexValue)
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(3);
            wait.PollingInterval = System.TimeSpan.FromMilliseconds(250);

            try
            {
                wait.Until(drv => isBorderColorChangedTo(drv, _locator, expectedColorHexValue));
            }
            catch (NoSuchElementException)
            {
            }
            catch (WebDriverTimeoutException)
            {
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Waits for the webelement to be clickable and ignores exceptions
        /// </summary>
        ///
        public static void ConditionalWait(this IWebElement element)
        {
            try
            {
                DefaultWait <IWebDriver> ConditionalWait = new DefaultWait <IWebDriver>(DriverContext.Driver);
                ConditionalWait.Timeout         = TimeSpan.FromSeconds(10);
                ConditionalWait.PollingInterval = TimeSpan.FromMilliseconds(250);
                ConditionalWait.IgnoreExceptionTypes(typeof(TargetInvocationException));
                ConditionalWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
                ConditionalWait.IgnoreExceptionTypes(typeof(InvalidOperationException));
                element = ConditionalWait.Until(ExpectedConditions.ElementToBeClickable(element));
            }

            catch (Exception e)
            {
                Console.Write("Error: " + e.ToString());
            }
        }
Exemplo n.º 7
0
        public bool FluentWait(IWebElement element)
        {
            _pollingWait                 = new DefaultWait <IWebElement>(element);
            _pollingWait.Timeout         = TimeSpan.FromSeconds("findTimeout".GetParsedValueByInt());
            _pollingWait.PollingInterval = TimeSpan.FromMilliseconds("pollingTime".GetParsedValueByInt());

            Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement e) =>
            {
                if (element.ElementVisibility(_wait) && element.ElementDisplayedOrEnabled(_wait))
                {
                    return(true);
                }

                return(false);
            });

            return(_pollingWait.Until(waiter));
        }
Exemplo n.º 8
0
 public static IWebElement FluentWaitbyXPath(this string element)
 {
     try
     {
         DefaultWait <IWebDriver> fluentWait = new DefaultWait <IWebDriver>(Drive.driver);
         fluentWait.Timeout         = TimeSpan.FromSeconds(3);
         fluentWait.PollingInterval = TimeSpan.FromMilliseconds(100);
         fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
         fluentWait.IgnoreExceptionTypes(typeof(ElementNotVisibleException));
         IWebElement searchElementbyXPath = fluentWait.Until(x => x.FindElement(By.XPath(element)));
         return(searchElementbyXPath);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Some Error:" + e.Message);
         return(null);
     }
 }
Exemplo n.º 9
0
        public static void WaitForElement(IWebElement element, double time)
        {
            DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);

            wait.Timeout         = TimeSpan.FromMinutes(time);
            wait.PollingInterval = TimeSpan.FromMilliseconds(250);

            Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
            {
                if (element.Displayed)
                {
                    return(true);
                }
                return(false);
            });

            wait.Until(waiter);
        }
        public void ElementClassDoesNotContain(string text)
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(5);
            wait.PollingInterval = System.TimeSpan.FromSeconds(1);

            try
            {
                wait.Until(drv => doesElementClassNotContain(drv, text));
            }
            catch (NoSuchElementException)
            {
            }
            catch (WebDriverTimeoutException)
            {
            }
        }
Exemplo n.º 11
0
        public static void WaitUntilElementExistsByAutomationId(string automationId, int timeoutInSeconds)
        {
            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(Session)
            {
                Timeout         = TimeSpan.FromSeconds(timeoutInSeconds),
                PollingInterval = TimeSpan.FromMilliseconds(100)
            };

            WindowsElement mainWindow = null;

            wait.IgnoreExceptionTypes(typeof(WebDriverException));
            wait.Until(driver =>
            {
                RefreshSession();
                mainWindow = Session.FindElementByAccessibilityId(automationId);
                return(mainWindow != null);
            });
        }
        // Help method to wait for element present on the view
        public void WaitForElementPresent()
        {
            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(WindowsDriver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromSeconds(1)
            };

            wait.IgnoreExceptionTypes(typeof(InvalidOperationException));
            wait.Until(d =>
            {
                if (GetByType().Equals("Id"))
                {
                    return(d.FindElementByAccessibilityId(GetByLocator()));
                }
                return(d.FindElement(Identifier));
            });
        }
Exemplo n.º 13
0
        /// <summary>
        ///     Wait until command evaluates to not-null value or throw exception other then <see cref="WebDriverException"/>.
        ///     Throw <see cref="WebDriverTimeoutException"/> if command expires eventually.
        /// </summary>
        /// <typeparam name="TTarget">Type of the command target</typeparam>
        /// <typeparam name="TReturn">Type of the command return result</typeparam>
        /// <param name="target">Command target</param>
        /// <param name="command">Command to evaluate</param>
        /// <param name="commandTimeout">Timeout after which command will became expired and exception will be thrown</param>
        /// <param name="pollingInterval">Determines how often command will be evaluated until it expires or succeeds</param>
        /// <param name="message">Error message used when command expires</param>
        /// <returns>Command result if it succeeded otherwise exception will thrown</returns>
        /// <exception cref="WebDriverTimeoutException">Thrown when command get timed out</exception>
        public static TReturn WaitFor <TTarget, TReturn>(
            this TTarget target,
            Func <TTarget, TReturn> command,
            TimeSpan commandTimeout,
            TimeSpan pollingInterval,
            String message = null) where TTarget : class
        {
            var wait = new DefaultWait <TTarget>(target)
            {
                Message         = message ?? String.Format("{0} expired after {1}", command, commandTimeout),
                PollingInterval = pollingInterval,
                Timeout         = commandTimeout
            };

            wait.IgnoreExceptionTypes(typeof(WebDriverException));

            return(wait.Until(command));
        }
Exemplo n.º 14
0
        public static IReadOnlyCollection <IWebElement> FindElements(this ISearchContext context, By by, int timeout)
        {
            var wait = new DefaultWait <ISearchContext>(context);

            wait.Timeout = TimeSpan.FromSeconds(timeout);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            return(wait.Until(dri => {
                var elem = dri.FindElements(by);
                if (elem.Count > 0)
                {
                    return elem;
                }
                else
                {
                    return null;
                }
            }));
        }
Exemplo n.º 15
0
        public static NgWebElement FindElement(this ISearchContext context, By by, int timeout = 20, bool displayed = false)
        {
            var wait = new DefaultWait <ISearchContext>(context)
            {
                Timeout = TimeSpan.FromSeconds(timeout)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            return(wait.Until(ctx => {
                var elem = ctx.FindElement(by);
                if (displayed && !elem.Displayed)
                {
                    return null;
                }

                return ((NgWebElement)(elem));
            }));
        }
Exemplo n.º 16
0
        public void WaitForElementToBeClickable(IWebElement element)
        {
            DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);

            wait.Timeout         = TimeSpan.FromMinutes(5);
            wait.PollingInterval = TimeSpan.FromMilliseconds(500);

            Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
            {
                if (ele.Displayed && ele.Enabled)
                {
                    return(true);
                }
                return(false);
            });

            wait.Until(waiter);
        }
        public void BorderColorToChangeTo(string expectedColorHexValue)
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(TIMEOUT);
            wait.PollingInterval = System.TimeSpan.FromMilliseconds(POLLING_INTERVAL);

            try
            {
                wait.Until(drv => isBorderColorChangedTo(drv, _locator, expectedColorHexValue));
            }
            catch (NoSuchElementException) { }
            catch (WebDriverTimeoutException)
            {
                System.Console.WriteLine("TimeOut while trying in BackgroundColorToChangeTo() => " + _locator.ToString()
                                         + ", expectedColorHexValue-" + expectedColorHexValue);
            }
        }
Exemplo n.º 18
0
 public static IWebElement FluentWaitbyCSS(this string elementName)
 {
     try
     {
         Drive.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
         DefaultWait <IWebDriver> fluentWait           = new DefaultWait <IWebDriver>(Drive.driver);
         fluentWait.Timeout         = TimeSpan.FromSeconds(1.5);
         fluentWait.PollingInterval = TimeSpan.FromMilliseconds(100);
         fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
         fluentWait.IgnoreExceptionTypes(typeof(ElementNotVisibleException));
         IWebElement searchElementbyCSS = fluentWait.Until(x => x.FindElement(By.CssSelector(elementName)));
         return(searchElementbyCSS);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Some Error:" + e.Message);
         return(null);
     }
 }
Exemplo n.º 19
0
        public static bool FulentWait_containsElementAttribute(IWebDriver driver, IWebElement element, string exp_attribute, string exp_value, int timeoutInSeconds = 15, int pollingInMillisec = 200)
        {
            try
            {
                string actual_value;
                DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);
                wait.Timeout         = TimeSpan.FromSeconds(timeoutInSeconds);
                wait.PollingInterval = TimeSpan.FromMilliseconds(pollingInMillisec);

                Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
                {
                    if (Helpers.Exists_safely(ele))
                    {
                        if (IsAttribtuePresent(ele, exp_attribute))
                        {
                            actual_value = ele.GetAttribute(exp_attribute).ToString();
                            //Console.WriteLine("Wait, expected contains attribute: '" + exp_value + "', but was: " + actual_value);
                            if (actual_value.Contains(exp_value))
                            {
                                //Console.WriteLine("Success, the item has attribute: " + actual_value);
                                return(true);
                            }
                        }
                    }
                    return(false);
                });
                //try
                //{
                wait.Until(waiter);    //this suchExeception
                //}
                //catch (NoSuchElementException)
                //{
                //    Assert.Fail("'Timeout' Locator:\n" + GetElementCssSelector(driver, element) + "\nFulentWait_containsElementAttribute");
                //    return false;
                //}
                return(true);
            }
            catch (Exception ex)
            {
                Assert.Fail("'Timeout'. Locator:\n" + GetElementCssSelector(driver, element) + "\n Test fail due to: {0}, {1}", ex.Message, ex.InnerException);
                return(false);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// WebDriverWaitUsingPolling
        /// </summary>
        /// <param name="element"></param>
        /// <param name="attributeName"></param>
        /// <param name="value"></param>
        public void WebDriverWaitUsingPolling(IWebElement element, string attributeName, string value, int timeOutInMin = 2, int timeIntervalInMilliSec = 250)
        {
            DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element)
            {
                Timeout         = TimeSpan.FromMinutes(timeOutInMin),
                PollingInterval = TimeSpan.FromMilliseconds(timeIntervalInMilliSec)
            };
            Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
            {
                string attrib = element.GetAttribute(attributeName);
                if (attrib.Contains(value))
                {
                    return(true);
                }
                return(false);
            });

            wait.Until(waiter);
        }
Exemplo n.º 21
0
        public void TestDefaultWait()
        {
            NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
            LinkHelper.ClickLink(By.LinkText("File a Bug"));
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
            ButtonHelper.ClickButton(By.Id("log_in"));
            ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);

            GenericHelper.WaitForWebElement(By.Id("bug_severity"), TimeSpan.FromSeconds(50));
            IWebElement element = GenericHelper.WaitForWebElementInPage(By.Id("bug_severity"), TimeSpan.FromSeconds(50));

            DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(ObjectRepository.Driver.FindElement(By.Id("bug_severity")));

            wait.PollingInterval = TimeSpan.FromMilliseconds(200);
            wait.Timeout         = TimeSpan.FromSeconds(50);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
            Console.WriteLine("After wait : {0}", wait.Until(changeOfValue()));
        }
Exemplo n.º 22
0
        public void TestDefaultWait()
        {
            NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
            LinkHelper.ClickLink(By.LinkText("File a Bug"));
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
            TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
            ButtonHelper.ClickButton(By.Id("log_in"));
            LinkHelper.ClickLink(By.LinkText("Testng"));
            ObjectRepository.Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));

            GenericHelper.WaitForWebElement(By.Id("bug_severity"), TimeSpan.FromSeconds(50));
            IWebElement ele = GenericHelper.WaitForWebElementInPage(By.Id("bug_severity"), TimeSpan.FromSeconds(50));

            DefaultWait<IWebElement> wait = new DefaultWait<IWebElement>(ObjectRepository.Driver.FindElement(By.Id("bug_severity")));
            wait.PollingInterval = TimeSpan.FromMilliseconds(200);
            wait.Timeout = TimeSpan.FromSeconds(50);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
            Console.WriteLine("After wait : {0}", wait.Until(this.Changeofvalue()));
        }
Exemplo n.º 23
0
        public void VerifyCurrentUrl()
        {
            try
            {
                string actualUrl = Driver.Url;
                var    wait      = new DefaultWait <DriverWrapper>(Driver);
                wait.Timeout         = TimeSpan.FromSeconds(TestConfiguration.PageLoadTimeout);
                wait.PollingInterval = TimeSpan.FromMilliseconds(TestConfiguration.PollingInterVal);;
                wait.Message         = "The actual page URL: '" + actualUrl + "' does not contain the expected page URL: '" + this.ExpectedUrl + "'.";
                wait.Until((d) => { return(d.Url.ToLower().Contains(ExpectedUrl.ToLower())); });

                Logger.Info("Verifed the actual URL: {0} contains the expected URL: {1}.", actualUrl, ExpectedUrl);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }
        private AppiumWebElement ScrollUntillItemFound(AndroidDriver <AppiumWebElement> driver, AppiumWebElement relativeTo, Func <AppiumWebElement> FindElementAction, int reties)
        {
            var wait = new DefaultWait <AndroidDriver <AppiumWebElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(1000)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            AppiumWebElement elementfound = null;

            elementfound = wait.Until(d =>
            {
                Flick(driver, relativeTo, UpOrDown.Up);
                return(FindElementAction());
            });

            return(elementfound);
        }
Exemplo n.º 25
0
        private static void WaitFluentUntil(By by)
        {
            try
            {
                Log.Info("WaitFluentUntil ..");
                ExtentReporter.NodeInfo("WaitFluentUntil ..");

                DefaultWait <IWebDriver> fluentWait = new DefaultWait <IWebDriver>(driver);
                fluentWait.Timeout         = TimeSpan.FromSeconds(Constants.Timeout);
                fluentWait.PollingInterval = TimeSpan.FromSeconds(1);
                fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
                IWebElement searchResult = fluentWait.Until(x => x.FindElement(by));
            }
            catch (Exception e)
            {
                Log.Error("Failed WaitFluentUntil | Exception: " + e.Message);
                ExtentReporter.NodeError("Failed WaitFluentUntil | Exception: " + e.Message);
            }
        }
        public static DefaultWait <IWebDriver> DefaultWait(
            IWebDriver driver, string element, propertyType type)
        {
            var wait = new DefaultWait <IWebDriver>(driver)
            {
                Timeout         = TimeSpan.FromSeconds(20),
                PollingInterval = TimeSpan.FromMilliseconds(250),
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.IgnoreExceptionTypes(typeof(InvalidOperationException));

            wait.Until(_ =>
            {
                if (type == propertyType.Id)
                {
                    _.FindElement(By.Id(element));
                }
                switch (type)
                {
                case propertyType.Id:
                    _.FindElement(By.Id(element));
                    break;

                case propertyType.Name:
                    _.FindElement(By.Name(element));
                    break;

                case propertyType.XPath:
                    _.FindElement(By.XPath(element));
                    break;

                case propertyType.Css:
                    _.FindElement(By.CssSelector(element));
                    break;

                default:
                    break;
                }
                return(true);
            });
            return(wait);
        }
        public void AddNewItem()
        {
            var driver = StartApp();
            // tap on second item
            var el1 = driver.FindElementByAccessibilityId("btnAdd");

            el1.Click();

            var elItemText = driver.FindElementByAccessibilityId("txtItemText");

            elItemText.Clear();
            elItemText.SendKeys("This is a new Item");

            var elItemDetail = driver.FindElementByAccessibilityId("txtDetailText");

            elItemDetail.Clear();
            elItemDetail.SendKeys("These are the details");

            var elSave = driver.FindElementByAccessibilityId("btnAdd");

            elSave.Click();


            var listview = driver.FindElementByAccessibilityId("listview");

            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(1000)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));

            var elementfound = wait.Until(d =>
            {
                FlickUp(driver, listview);
                return(d.FindElementByName("This is a new Item"));
            });

            Assert.IsTrue(elementfound != null);

            driver.CloseApp();
        }
Exemplo n.º 28
0
        public void AddNewItem()
        {
            var driver = StartApp();
            // tap on second item
            var addButton = driver.FindElementByName("AddNewItem");

            addButton.Click();

            var AddDialogWindow = driver.FindElementByAccessibilityId("NewItemForm");

            var inputFieldItem = AddDialogWindow.FindElementByName("ItemText");

            inputFieldItem.Clear();
            inputFieldItem.SendKeys("New Item Text");

            var InputFieldItemDetail = AddDialogWindow.FindElementByName("ItemDetail");

            InputFieldItemDetail.Clear();
            InputFieldItemDetail.SendKeys("New item details text");

            //close the dialog
            var AddButton = AddDialogWindow.FindElementByAccessibilityId("button1");

            AddButton.Click();

            var listview = driver.FindElementByAccessibilityId("listView1");

            var wait = new DefaultWait <WindowsDriver <WindowsElement> >(driver)
            {
                Timeout         = TimeSpan.FromSeconds(60),
                PollingInterval = TimeSpan.FromMilliseconds(1000)
            };

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));

            var elementfound = wait.Until(d =>
            {
                FlickUp(driver, listview);
                return(d.FindElementByName("New Item Text"));
            });

            driver.CloseApp();
        }
        private IWebElement GetElement(IWebDriver driver, By locator)
        {
            DefaultWait <IWebDriver> wait = new DefaultWait <IWebDriver>(_driver);

            wait.Timeout         = System.TimeSpan.FromSeconds(TIMEOUT / 4);
            wait.PollingInterval = System.TimeSpan.FromMilliseconds(POLLING_INTERVAL);
            try
            {
                wait.Until(drv => isElementAvailableNow(drv, _locator));
                return(driver.FindElement(locator));
            }
            catch (NoSuchElementException) { }
            catch (WebDriverTimeoutException)
            {
                System.Console.WriteLine("TimeOut while trying in GetElement() => " + locator.ToString());
            }

            return(null);
        }
Exemplo n.º 30
0
        public static void DefaultWait(this IWebElement element, int waitInSec)
        {
            DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);

            wait.Timeout         = TimeSpan.FromSeconds(waitInSec);
            wait.PollingInterval = TimeSpan.FromMilliseconds(250);

            Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
            {
                String id = element.GetAttribute("id");
                if (!string.IsNullOrEmpty(id))
                {
                    return(true);
                }
                Console.WriteLine("Element {0} is still not clickable" + id);
                return(false);
            });

            wait.Until(waiter);
        }
Exemplo n.º 31
0
        public static void WaitUntilElementIs(this ISearchContext iSearchContext, By by, string expectedTextValue)
        {
            var wait = new DefaultWait <ISearchContext>(iSearchContext);

            wait.Timeout = TimeSpan.FromSeconds(20);
            wait.Until(ctx =>
            {
                var elem = ctx.FindElement(by);
                if (!elem.Enabled || !elem.Displayed)
                {
                    return(null);
                }
                if (elem.GetAttribute("value") == expectedTextValue)
                {
                    return(elem);
                }

                return(null);
            });
        }
        private static void WaitUntilImpl <T>(Func <IEnumerable <ICriteria <T> >, T, bool> impl, T input, TimeSpan timeout, params ICriteria <T>[] criteria)
        {
            // Note: We ignore the input here, we're just using the timing functionality
            // of the wait
            var wait = new DefaultWait <object>(new object());

            wait.Timeout = timeout;
            try
            {
                wait.Until(p =>
                {
                    return(impl(criteria, input));
                });
            }
            catch (WebDriverTimeoutException ex)
            {
                var failures = criteria.Failures(input);
                throw new WebDriverTimeoutException(string.Format("Timed out after {0} seconds, waiting for {1} criteria.  The following criteria were not met: {2}", wait.Timeout.TotalSeconds, criteria.Count(), failures.Description(input)), ex);
            }
        }
Exemplo n.º 33
0
        public static IWebElement FindElementFromHere(this IWebElement element, By locator)
        {
            try
            {
                var wait = new DefaultWait <IWebElement>(element)
                {
                    Timeout         = TimeSpan.FromSeconds(30),
                    PollingInterval = TimeSpan.FromMilliseconds(500)
                };
                wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NotFoundException),
                                          typeof(StaleElementReferenceException));
                var webElement = wait.Until(ele => ele.FindElement(locator));

                return(webElement);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public static bool MatchCondition(
            this IWebElement element, Func<IWebElement, bool> predicate, int timeoutInSeconds)
        {
            if (timeoutInSeconds <= 0) return predicate(element);

            var wait = new DefaultWait<IWebElement>(element)
            {
                Timeout = TimeSpan.FromSeconds(timeoutInSeconds),
                PollingInterval = TimeSpan.FromMilliseconds(500.0)
            };
            return wait.Until(predicate);
        }
Exemplo n.º 35
0
		private static IWebElement WaitTill(this IWebElement element, int timeOutSeconds, Func<IWebElement, bool> condition, string desc)
		{
			timeOutSeconds *= Settings.Default.WaitFactor;

			Trace.Write(BasePage.TraceLevelLow + desc);
			Trace.WriteLine("Max waiting time: " + timeOutSeconds + " sec");

			var wait = new DefaultWait<IWebElement>(element);
			wait.Timeout = TimeSpan.FromSeconds(timeOutSeconds);
				
			wait.Until(condition);

			return element;
		}