Ejemplo n.º 1
0
        /// <summary>
        /// Overloads the FindElement function to include support for the jQuery selector class
        /// </summary>
        public static IWebElement FindElement(this RemoteWebDriver driver, By.JQueryBy by)
        {
            //First make sure we can use jQuery functions
            driver.LoadJQuery();

            //Execute the jQuery selector as a script
            var element = driver.ExecuteScript("return $(\"" + by.Selector + "\").get(0)") as IWebElement;

            if (element != null)
            {
                return(element);
            }
            throw new NoSuchElementException("No element found with jQuery command: jQuery" + by.Selector);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Overloads the FindElements function to include support for the jQuery selector class
        /// </summary>
        public static ReadOnlyCollection <IWebElement> FindElements(this RemoteWebDriver driver, By.JQueryBy by)
        {
            //First make sure we can use jQuery functions
            driver.LoadJQuery();

            //Execute the jQuery selector as a script
            var collection =
                driver.ExecuteScript("return $(\"" + by.Selector + "\").get()") as ReadOnlyCollection <IWebElement> ??
                new ReadOnlyCollection <IWebElement>(new List <IWebElement>());

            //Unlike FindElement, FindElements does not throw an exception if no elements are found
            //and instead returns an empty list
            return(collection);
        }