/// <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 IWebElement element = driver.ExecuteScript("return jQuery" + by.Selector + ".get(0)") as IWebElement; if (element != null) { return(element); } else { throw new NoSuchElementException("No element found with jQuery command: jQuery" + by.Selector); } }
/// <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 ReadOnlyCollection <IWebElement> collection = driver.ExecuteScript("return jQuery" + by.Selector + ".get()") as ReadOnlyCollection <IWebElement>; //Unlike FindElement, FindElements does not throw an exception if no elements are found //and instead returns an empty list if (collection == null) { collection = new ReadOnlyCollection <IWebElement>(new List <IWebElement>()); //empty list } return(collection); }