Exemplo n.º 1
0
        public void What_Is_Implicit_Wait_And_Explicit_Wait()
        {
            //Implicit wait- Asking the browser to wait for amount of time driver should wait while searching for an element if it is not present immediately
            //If the element is found beofre the time seciified the next step will be executed without waiting for remaining time mentioned in implicit wait.
            chromedriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            //Explicit Wait- Specific wait
            OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(chromedriver, TimeSpan.FromSeconds(10));
            wait.Message = "";                                       //Gets for sets the message to be displayed when time expires
            wait.IgnoreExceptionTypes();                             //Configures this instance to ignore the specific exceptions while waiting on the condition
            wait.PollingInterval = TimeSpan.FromMilliseconds(100);   //Gets or sets how often the condition should be evaluated. The deafult timeout is 500milliseond
            wait.Until(x => x.FindElements(By.XPath("")).Count > 1); //Condtion till the wait should be applied. Throws exception when timeout expires.
            //wait.Until(ExpectedConditions.)
            wait.Until(ExpectedConditions.AlertIsPresent());
            //An expectation for checking that an element is present on the DOM of a page
            //This does not necessarily mean that the element is visible.
            //// Returns:
            //     The OpenQA.Selenium.IWebElement once it is located.
            wait.Until(ExpectedConditions.ElementExists(By.Id("elem")));

            // Summary:
            //     An expectation for checking that an element is present on the DOM of a page and
            //     visible. Visibility means that the element is not only displayed but also has
            //     a height and width that is greater than 0.
            // Returns:
            //     The OpenQA.Selenium.IWebElement once it is located and visible.
            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("elem")));

            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("elem")));

            wait.Until(ExpectedConditions.TextToBePresentInElement(chromedriver.FindElement(By.Id("elem")), ""));
            // An expectation for checking the title of a page.
            wait.Until(ExpectedConditions.TitleIs(""));
            wait.Until(ExpectedConditions.UrlContains(""));
        }