Hunter Marshall
Hunter Marshall

Reputation: 211

Nightwatch.js using data attributes

I'm new to nightwatch.js. I work in QA and the developers don't want to use ids or classes for the automated tests. They want to use data-test. So for example data-test="nav-button".

Is there way to find elements and click elements using this attribute in nightwatch.js?

Upvotes: 5

Views: 2836

Answers (1)

hjcoder18
hjcoder18

Reputation: 479

This is actually pretty simple. Just put the data-test in square brackets after the element type. See below for examples. In these examples, the data-test attribute is in an anchor tag.

.waitForElementVisible('a[data-test=nav-button]') .click(a[data-test=nav-button])

Upvotes: 5

Related Questions