示例#1
0
        public static void WaitForElementExists(this By by, IWebDriver driver, TimeSpan?timeout = null, bool suppressException = true)
        {
            var waitTimeout = timeout.IsNotNull() ? timeout.Value : AppConfig.ElementLoadWaitTime;

            try
            {
                var wait = new WebDriverWait(driver, waitTimeout);
                wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
                wait.Until(d => by.Exists(d));
            }
            catch (WebDriverTimeoutException ex)
            {
                Console.WriteLine("Element Timeout Exception. " + ex.Message);
                if (!suppressException)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown. Please see Exception details " + ex.Message);
                if (!suppressException)
                {
                    throw;
                }
            }
        }
示例#2
0
        public static void ActionClick(this By selector)
        {
            selector.WaitForElementToBeClickable();
            if (!selector.Exists())
            {
                return;
            }

            Browser.WebDriver.FindElement(selector).Click();
        }
示例#3
0
        public static void ClearField(this By selector)
        {
            selector.WaitForElement();
            if (!selector.Exists())
            {
                return;
            }

            Browser.WebDriver.FindElement(selector).Clear();
        }
示例#4
0
        public static void ActionSendKeys(this By selector, string text)
        {
            selector.WaitForElement();
            if (!selector.Exists() || string.IsNullOrEmpty(text))
            {
                return;
            }

            selector.ClearField();
            Browser.WebDriver.FindElement(selector).SendKeys(text);
        }