OpenQA.Selenium.By.CssSelector C# (CSharp) Méthode

CssSelector() public static méthode

Gets a mechanism to find elements by their cascading stylesheet (CSS) selector.
public static CssSelector ( string cssSelectorToFind ) : By
cssSelectorToFind string The CSS selector to find.
Résultat By
        public static By CssSelector(string cssSelectorToFind)
        {
            if (cssSelectorToFind == null)
            {
                throw new ArgumentNullException("cssSelectorToFind", "Cannot find elements when name CSS selector is null.");
            }

            By by = new By();
            by.findElementMethod =
                (ISearchContext context) => ((IFindsByCssSelector)context).FindElementByCssSelector(cssSelectorToFind);
            by.findElementsMethod =
                (ISearchContext context) => ((IFindsByCssSelector)context).FindElementsByCssSelector(cssSelectorToFind);

            by.description = "By.CssSelector: " + cssSelectorToFind;
            return by;
        }

Usage Example

        /// <summary>
        /// Click the 'Edit' button for a position category
        /// </summary>
        /// <param name="categoryName">The name of the category to edit</param>
        public void EditPositionCategory(string categoryName = null)
        {
            // if the category isnt specified, find the first category in the list
            if (String.IsNullOrWhiteSpace(categoryName))
            {
                categoryName = _driver.FindElement(By.CssSelector("#maintbl > tbody > #rowNbr0 > td > b")).Text;
            }

            ((IJavaScriptExecutor)_driver).ExecuteScript("EditPositionCategory('" + categoryName + "')");
        }
All Usage Examples Of OpenQA.Selenium.By::CssSelector