#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
📋 FREE · SEARCHABLE

Selenium Locators Cheat Sheet: Every Pattern in One Searchable Page

Find the XPath, CSS or wait syntax you need in seconds.

  • 🔎 Instant search
  • 🌳 XPath axes explained
  • ⏱️ Wait syntax

How to use the Selenium Locators Cheat Sheet

  1. 1. Search or filterType a word like sibling or wait, or pick a category.
  2. 2. Copy the patternCopy the items you need into your notes or code.
  3. 3. DownloadSave the full or filtered sheet as a text file.

What is on the sheet

The cheat sheet groups locators the way you use them: the eight By strategies in Selenium WebDriver, common CSS patterns (attribute, starts-with, child, sibling, nth-child), XPath patterns (relative paths, text matching, contains, starts-with, index), XPath axes and waits.

One of the most useful lines is the label-to-input pattern //label[text()='Email']/following-sibling::input, which finds a field by its visible label even when the input has no id. CSS cannot move sideways or upwards like this, which is when XPath earns its place. Each item shows the syntax, a one-line explanation and, where useful, an example you can paste straight into a test.

Rules of thumb

  • Priority: id → data-testid → name → CSS → XPath. Choose the most stable, not the cleverest.
  • Never use absolute XPath copied from DevTools for real tests.
  • Use explicit waits (WebDriverWait with a condition), not fixed sleeps, and do not mix implicit and explicit waits.
  • Test in the console first: $$("css") and $x("//xpath") in Chrome DevTools.
  • Frames and shadow DOM need a switch or a shadow root before you can find inner elements.

Syntax shown is for Selenium 4 in Java and Python. Older Selenium 3 helpers such as find_element_by_id were removed in Selenium 4. Try any pattern on your own HTML with the XPath tester, or let the locator generator suggest one.

Frequently asked questions

Is CSS faster than XPath?

In modern browsers the difference is small. Choose whichever gives the clearer, more stable locator.

Does this apply to Playwright or Cypress?

The CSS and XPath patterns do. The By and wait syntax is Selenium-specific.

Is the Selenium Locators Cheat Sheet free?

Yes, the Selenium Locators Cheat Sheet is free. The first time you download the sheet, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.

More free tools

See all free tools