MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / withClass

Method withClass

lib/locator.js:391–396  ·  view source on GitHub ↗

* Find an element with all of the provided CSS classes (word-exact match). * Accepts variadic class names; all must be present. * * Example: * locate('button').withClass('btn-primary', 'btn-lg') * * @param {...string} classes * @returns {Locator}

(...classes)

Source from the content-addressed store, hash-verified

389 * @returns {Locator}
390 */
391 withClass(...classes) {
392 if (!classes.length) return this
393 const predicates = classes.map(c => `contains(concat(' ', normalize-space(@class), ' '), ' ${c} ')`)
394 const xpath = sprintf('%s[%s]', this.toXPath(), predicates.join(' and '))
395 return new Locator({ xpath })
396 }
397
398 /**
399 * Find an element with none of the provided CSS classes.

Callers 1

locator_test.jsFile · 0.80

Calls 1

toXPathMethod · 0.95

Tested by

no test coverage detected