Example #1
0
        /// <summary>
        /// Finds a list of elements that match the class name supplied
        /// </summary>
        /// <param name="className">CSS class Name on the element</param>
        /// <returns>ReadOnlyCollection of IWebElement object so that you can interact with those objects</returns>
        /// <example>
        /// <code>
        /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
        /// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByClassName("classname")
        /// </code>
        /// </example>
        public ReadOnlyCollection <IWebElement> FindElementsByClassName(string className)
        {
            string selector = By.EscapeCssSelector(className);

            if (selector.Contains(" "))
            {
                // Finding elements by class name with whitespace is not allowed.
                // However, converting the single class name to a valid CSS selector
                // by prepending a '.' may result in a still-valid, but incorrect
                // selector. Thus, we short-ciruit that behavior here.
                throw new InvalidSelectorException("Compound class names not allowed. Cannot have whitespace in class name. Use CSS selectors instead.");
            }

            return(this.FindElements("css selector", "." + selector));
        }
Example #2
0
        /// <summary>
        /// Finds the first element in the page that matches the ID supplied
        /// </summary>
        /// <param name="id">ID of the Element</param>
        /// <returns>ReadOnlyCollection of Elements that match the object so that you can interact that object</returns>
        /// <example>
        /// <code>
        /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
        /// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsById("id")
        /// </code>
        /// </example>
        public ReadOnlyCollection <IWebElement> FindElementsById(string id)
        {
            string selector = By.EscapeCssSelector(id);

            if (string.IsNullOrEmpty(selector))
            {
                // Finding multiple elements with an empty ID will return
                // an empty list. However, finding by a CSS selector of '#'
                // throws an exception, even in the multiple elements case,
                // which means we need to short-circuit that behavior.
                return(new List <IWebElement>().AsReadOnly());
            }

            return(this.FindElements("css selector", "#" + selector));
        }
 /// <summary>
 /// Finds a list of elements that match the class name supplied
 /// </summary>
 /// <param name="className">CSS class name of the elements on the page</param>
 /// <returns>ReadOnlyCollection of IWebElement object so that you can interact with those objects</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByClassName("classname")
 /// </code>
 /// </example>
 public virtual ReadOnlyCollection <IWebElement> FindElementsByClassName(string className)
 {
     return(this.FindElements("css selector", "." + By.EscapeCssSelector(className)));
 }
 /// <summary>
 /// Finds the first element in the page that matches the CSS Class supplied
 /// </summary>
 /// <param name="className">CSS class name of the element on the page</param>
 /// <returns>IWebElement object so that you can interact that object</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
 /// IWebElement elem = driver.FindElementByClassName("classname")
 /// </code>
 /// </example>
 public virtual IWebElement FindElementByClassName(string className)
 {
     return(this.FindElement("css selector", "." + By.EscapeCssSelector(className)));
 }
 /// <summary>
 /// Finds the first element in the page that matches the ID supplied
 /// </summary>
 /// <param name="id">ID of the Element</param>
 /// <returns>ReadOnlyCollection of Elements that match the object so that you can interact that object</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsById("id")
 /// </code>
 /// </example>
 public virtual ReadOnlyCollection <IWebElement> FindElementsById(string id)
 {
     return(this.FindElements("css selector", "#" + By.EscapeCssSelector(id)));
 }
 /// <summary>
 /// Finds the first element in the page that matches the ID supplied
 /// </summary>
 /// <param name="id">ID of the element</param>
 /// <returns>IWebElement object so that you can interact with that object</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
 /// IWebElement elem = driver.FindElementById("id")
 /// </code>
 /// </example>
 public virtual IWebElement FindElementById(string id)
 {
     return(this.FindElement("css selector", "#" + By.EscapeCssSelector(id)));
 }