예제 #1
0
        public static bool SendKeysToElement(this IWebDriver driver, By by, string text, TimeSpan timeout)
        {
            // Validate parameters
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (by == null)
            {
                throw new ArgumentNullException(nameof(by));
            }

            if (String.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            // Attempt to type in the element
            if (IWebDriverExtensions.ElementExists(driver, by, timeout))
            {
                driver.FindElement(by).MoveToAndSendKeys(driver, text);

                return(true);
            }

            return(false);
        }
예제 #2
0
        public static void WaitForElement(this IWebDriver driver, By by, TimeSpan timeout)
        {
            // Validate parameters
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (by == null)
            {
                throw new ArgumentNullException(nameof(by));
            }

            // Attempt to wait for the element
            WebDriverWait wait = new WebDriverWait(driver, timeout);

            wait.Until(x => IWebDriverExtensions.ElementExists(x, by));
        }
예제 #3
0
        public static bool ElementExists(this IWebDriver driver, By by, TimeSpan timeout)
        {
            // Validate parameters
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (by == null)
            {
                throw new ArgumentNullException(nameof(by));
            }

            // Attempt to wait until the element is found
            if (timeout.TotalMilliseconds > 0)
            {
                WebDriverWait wait = new WebDriverWait(driver, timeout);

                return(wait.Until(x => IWebDriverExtensions.ElementExists(x, by)));
            }

            return(IWebDriverExtensions.ElementExists(driver, by));
        }
예제 #4
0
        public static bool ClickElement(this IWebDriver driver, By by, TimeSpan timeout)
        {
            // Validate parameters
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (by == null)
            {
                throw new ArgumentNullException(nameof(by));
            }

            // Attempt to click the element
            if (IWebDriverExtensions.ElementExists(driver, by, timeout))
            {
                driver.FindElement(by).MoveToAndClick(driver);
                driver.WaitFor(TimeSpan.FromSeconds(0.25));

                return(true);
            }

            return(false);
        }