Ejemplo n.º 1
0
 public static void ClickElement(this IWebElement e)
 {
     try
     {
         WaitUntilDisplayed(e);
         e.Click();
     }
     catch (TargetInvocationException)
     {
         //TODO make this more realistic for chrome.
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
     catch (ElementClickInterceptedException)
     {
         //TODO make this more realistic for chrome.
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
     catch (ElementNotInteractableException)
     {
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
 }
Ejemplo n.º 2
0
        public static void WaitUntilClickable(this IWebElement e)
        {
            var driver          = WebDriverSupport.SupportDriver();
            var isClickableWait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));

            isClickableWait.Until(ExpectedConditions.ElementToBeClickable(e));

            e.Click();
        }
Ejemplo n.º 3
0
        public static string WaitForText(this IWebElement e, string expectedText, int timeout = 10)
        {
            var watch        = new Stopwatch();
            var driver       = WebDriverSupport.SupportDriver();
            var textContains = false;

            watch.Start();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
            while (!textContains && watch.Elapsed.TotalMilliseconds <= timeout.ToMilliseconds())
            {
                try
                {
                    if (e.Text.Contains(expectedText))
                    {
                        return(e.Text);
                    }
                }
                catch
                {
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private static bool WaitHandler(IWebElement e, int timeout, ElementOptions option, string text = "")
        {
            var watch  = new Stopwatch();
            var driver = WebDriverSupport.SupportDriver();
            var result = false;

            watch.Start();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
            while (watch.Elapsed.TotalMilliseconds <= timeout.ToMilliseconds() && !result)
            {
                try
                {
                    switch (option)
                    {
                    case ElementOptions.Displayed:
                        if (e.Displayed)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.NotDisplayed:
                        if (e == null || !e.Displayed)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.Enabled:
                        if (e.Enabled)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.SelectOptionDisplayed:
                        if (e.FindElements(By.TagName("option")).Count(x => x.Text.Contains(text)) > 0)
                        {
                            result = true;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(option), option, null);
                    }
                }
                catch (NoSuchElementException)
                {
                    if (option == ElementOptions.NotDisplayed)
                    {
                        result = true;
                    }
                }
                catch (StaleElementReferenceException)
                {
                    if (option == ElementOptions.NotDisplayed)
                    {
                        result = true;
                    }
                }
                catch
                {
                    //Ignored
                }
            }

            // if (watch.Elapsed.Seconds > 1) Log.Info($"Waited for {watch.Elapsed.Seconds} seconds for the element state {option}");

            return(result);
        }
Ejemplo n.º 5
0
 public static void NavigateUrl(string url)
 {
     WebDriverSupport.SupportDriver().Navigate().GoToUrl(AppConfigManager.GetBaseUrl());
 }