Targeting a tour step at a stable element
Choose a stable selector
Attach each tour step to an element that survives redesigns. Prefer a data attribute such as data-tour-step="create-project" over a fragile class like .btn-primary or an XPath that breaks when a wrapper div is added. Ask the frontend team to add the attribute once; the tour can survive CSS refactors, theme changes, and A/B test variants.
Fallback chain
If the attribute is missing, define a short fallback list in the tour configuration: first the data attribute, then a unique ID, then a semantic role plus accessible name. The tour engine can try each in order and proceed when one matches. Document the chain so future maintainers know the priority.
Worked example: dashboard "New Project" button
Original markup: <button class="btn btn-green" id="new-proj">New Project</button>. Team adds data-tour-step="create-project". Tour config:
{
"step": "create-project",
"selectors": [
"[data-tour-step='create-project']",
"#new-proj",
"button[aria-label='Create new project']"
]
}
Six months later a redesign changes the button to <a class="cta" href="/projects/new" data-tour-step="create-project">Start a project</a>. The first selector still matches; the tour can continue without edits.
Exception: shadow DOM
If the target element lives inside a closed shadow root, the data attribute cannot be reached from the main document. In that case, coordinate with the component owner to expose a part="tour-create-project" or provide a JavaScript hook that returns the element. The tour step can call the hook instead of querying the DOM directly.
Result: the "Create Project" step can remain anchored through multiple redesigns without tour maintenance.
Related: Onboarding Tours features.
