* 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)
| 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. |