Skip to main content

Writing custom selectors with crusher

What you'll learn?
  • Different ways to write selectors

Often, when writing complex test flows or to ensure stability across tests, you'll have to write custom selectors for your test. This guide will go through different ways to write selectors and their advantages.

Writing Selectors

Depending on your web app and your needs, there are different approaches you can choose when writing selectors.

🦖   Pros:
  1. No need to go through the DOM tree to write text selectors.
  2. Easily locate elements without any id/classNames.

Elements containing some text

text=Hello world

This will match all the elements containing this text inside them.

Elements containing exactly the same text

text="Hello world"

This will match all the elements containing exactly the same text ("Hello world"). E.g a "Hello world" button.

Resources

  1. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
  2. https://playwright.dev/docs/selectors
  3. https://devhints.io/xpath
Was this doc helpful?
yes
could be better
by