Page under test
CSS

    Challenges

      CSS selector cheat sheet

      Every example below works in the playground above. In both Selenium (By.cssSelector) and Playwright (page.locator), these are the same selectors you'd use in a stylesheet.

      SelectorWhat it selects
      #nl-emailThe element with that id.
      .priceEvery element with that class.
      .nav-link.activeElements with both classes (no space between them).
      [data-sku='B200']Exact attribute value.
      [data-testid^='add-']Attribute starts with ($= ends with, *= contains).
      nav aDescendants: every a anywhere inside nav.
      .info > .priceDirect children only.
      h2 + .priceThe element immediately after an h2.
      h2 ~ spanAny later sibling of an h2.
      .product:nth-child(2)The second child of its parent (if it's a .product).
      li:first-child, li:last-childFirst / last child.
      .product:not(.sale)Exclude matches.
      button:disabled, input:checkedElements in a particular state.
      li:has(.out-of-stock)Elements that contain a match — the closest CSS gets to walking up.

      What CSS can't do

      CSS can't match on visible text, and apart from :has() it can't move up the tree. For "the row whose cell says #1002", use the XPath Playground, or Playwright's getByText and filter({ hasText }) in the Playwright Locator Playground.