Select Page
Codoid Blog

Selenium WebDriver-CSS Selector

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

selenium locators

CSS selector is used by browsers to target specific HTML elements and apply styles. For web browser automation, Selenium webdriver uses CSS selectors to locate and perform an action on an object instead of applying a style.

Selenium RC was using Sizzle-JavaScript CSS selector engine for CSS locating but in WebDriver, native browser support is used for CSS queries. If a browser does not have native support, then Sizzle will be used.

Tips for writing better CSS Selector:

  • Never use the start selector (*). If it is used in CSS selector, then the browser will assess every element.
  • CSS selectors are evaluated from right to left. Make sure to give more filter criteria for the rightmost selector in the selector chain.
  • Avoid Descendant selectors as much as possible.
  • Use ID and Class selectors since it matches quickly than other selectors.
  • Avoid lengthy selectors.
  • Useful CSS Selector Examples:

  • Selenium Tips: CSS Selectors
  • CSS nth-child Selector
  •  
    I hope it helps.

    Written by: Asiq Ahamed

    Comments(0)

    Submit a Comment

    Your email address will not be published. Required fields are marked *

    Talk to our Experts

    Amazing clients who
    trust us


    poloatto
    ABB
    polaris
    ooredo
    stryker
    mobility