This step registers multiple named XPath selectors in a single data table. Each row has two columns: the human-readable name and the XPath expression. Rows with an empty name or expression are silently skipped. The step is the bulk equivalent of When I add ... xpath selector and is best placed in a Given block at the top of a scenario where several XPath-based locators are needed together.
Registered XPath names go into the same registry consulted by position, visibility, focus, and click steps. Because the CSS registry is checked first, an XPath entry with the same name as a CSS entry will never be reached during resolution. Use distinct names, or rely on this priority intentionally when you want a CSS fallback to override XPath. As with CSS bulk registration, calling this step multiple times in a scenario accumulates entries and later rows override earlier rows with the same name.
Accepted phrasings
Given I define xpath selectors:
| name | xpath-expression |
Given we define xpath selectors:
| name | xpath-expression |
When I define xpath selectors:
| name | xpath-expression |
And I define xpath selectors:
| name | xpath-expression |
Given define xpath selectors:
| name | xpath-expression |
Examples
Given I define xpath selectors:
| first heading | //h1[1] |
| first subline | //h3[1] |
Given I define xpath selectors:
| active tab | //li[contains(@class,'active')]/a |
| last nav item | //nav//a[last()] |
Given I define xpath selectors:
| first table row | //table/tbody/tr[1] |
| first table cell | //table/tbody/tr[1]/td[1] |
Given we define xpath selectors:
| login link | //a[contains(normalize-space(.),'Login')] |
In a real scenario
Scenario: Article page heading hierarchy renders in correct order
Given I navigate to "https://example.org/articles/getting-started"
And I define xpath selectors:
| page title | //h1[1] |
| first section | //h2[1] |
| first para | //article//p[1] |
And I define css selectors:
| article body | article.node-body |
Then I see visible page title, first section, first para
And I see page title above first section
And I see first section above first para
And I see first para inside of article body