Selenium WebDriver-CSS Selector

Selenium WebDriver-CSS Selector

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:

Hope, it is helpful.

Abhay Bharti

JavaScript Developer | Principal QE Engineer | Playwright/Selenium Expert

8y

Good Piece of information..

To view or add a comment, sign in

More articles by 🦀 Asiq Ahamed - Rustacean

  • Which is Better: Selenium or Playwright?

    Test automation has come a long way, and if you’re deciding between Selenium and Playwright, you’re not alone! Selenium…

  • How to Reduce Software Release Delays with Efficient QA Practices

    In the fast-paced world of software development, release delays can be a frustrating reality. But what if I told you…

  • Leading QA Teams Across Time Zones and Cultures

    Have you ever found yourself hopping onto a late-night video call to resolve a QA issue—only to discover that your…

    2 Comments
  • Learning Exploratory Testing from Carl

    When I was coaching my team on how to create robust automated regression suite and reduce false positives, I posted the…

    3 Comments
  • Why Testers Attitude Matters A Lot In Agile Testing

    One day my six months baby woke up and started crying in the cradle. I heard the cry and started swinging the cradle.

    4 Comments
  • An Introduction to Serenity/JS

    Before starting this article, I would like to thank Jan Molak who introduced Serenity/JS to me. Let's start with the…

  • WebDriver Frame & iFrame Handling

    Every Selenium script developer is aware of how to handle frame and iFrame. This is a short article; however, the…

  • Understanding Asynchronous WebdriverJS

    While I was working on a proof of concept using CucumberJS and Selenium-WebDriverJs, I found a few interesting concepts…

    7 Comments

Insights from the community

Others also viewed

Explore topics