Selectors Guide
You donβt need to be an expert to use selectors. If you can inspect an element, you can create a tour.
π Quick Start (Do This First)
- Right-click any element on your page
- Click **Inspect**
- Find the element in the HTML
- Use one of these:
- `#id` β if element has an id
- `.class` β if it has a class
- `button` / `div` β basic tags
Example:
{
selector: "#login-btn"
}
π§ Simple Rules (Follow These)
- Prefer **id (`#id`)** β most stable
- Use **class (`.class`)** if no id
- Avoid deep selectors like:
div > div > span:nth-child(2)
π These break easily
β Best Practices
1. Use Unique Selectors
Good:
#submit-btn
Bad:
.button
2. Add Your Own Attributes (Recommended)
If your UI doesnβt have good selectors, add this:
<button data-tour="start-btn">Start</button>
Then use:
{
selector: '[data-tour="start-btn"]'
}
π This is the most reliable method
3. Keep It Stable
Avoid:
- Auto-generated class names
- Framework-specific dynamic ids
π Common Selector Types
ID Selector
#header
Class Selector
.navbar
Attribute Selector (Best for production)
[data-tour="menu"]
Tag Selector
button
β‘ Extended Selector Features (NavigateMe)
These are power features that make your tours smarter and easier to target.
π€ `:contains(text)`
Select elements containing specific text.
button:contains(Start)
π Matches any button that includes "Start"
π― `:exact`
Use with :contains() for exact text match.
button:contains(Start):exact
π Matches only elements with exact text "Start"
π’ `:nth(index)`
Select element at a specific position (0-based index).
.card:nth(2)
π Selects the 3rd .card
π `:last`
Select the last matching element.
.card:last
π Selects the last .card
π§ͺ Combining Features
You can combine selectors with features:
button:contains(Next):nth(1)
π Second button containing "Next"
.menu-item:contains(Settings):exact
π Exact match for "Settings"
β οΈ Guidelines for Extended Selectors
- Use `:contains()` when no id/class is available
- Use `:exact` to avoid wrong matches
- Use `:nth()` when multiple elements exist
- Prefer `[data-tour]` over complex logic when possible
π§ͺ Debugging Tips
Element not found?
- Check selector syntax
- Ensure element exists on load
- Try removing advanced filters (`:nth`, `:contains`)
Wrong element selected?
- Add `:exact`
- Use `:nth()`
- Switch to `[data-tour]`
π‘ Pro Tip
Start simple β refine later
Donβt over-engineer selectors. Get the tour working first, then improve.
π― Example Tour Step
{
selector: 'button:contains(Login):exact',
content: "Click here to login"
}
π Summary
- Use `#id` when possible
- Use `[data-tour="..."]` for reliability
- Use `:contains`, `:exact`, `:nth`, `:last` when needed
- Avoid complex CSS chains
Thatβs it. Youβre ready to build powerful, flexible tours.