Contains
Methods
Table of Contents
contains
Returns a boolean representing whether an element or a set of elements contains the specified text.
Parameters
selector
string CSS selector of the element to checkuserOptions
(optional, default{}
)options
Object Additional optionsoptions.scope
string Nests provided scope within parent’s scopeoptions.at
number Reduce the set of matched elements to the one at the specified indexoptions.resetScope
boolean Override parent’s scopeoptions.multiple
boolean Check if all elements matched by selector contain the subtextoptions.testContainer
string Context where to search elements in the DOM
Examples
// Lorem <span>ipsum</span>
const page = PageObject.create({
spanContains: PageObject.contains('span')
});
assert.ok(page.spanContains('ipsum'));
// <span>lorem</span>
// <span>ipsum</span>
// <span>dolor</span>
const page = PageObject.create({
spansContain: PageObject.contains('span', { multiple: true })
});
// not all spans contain 'lorem'
assert.notOk(page.spansContain('lorem'));
// <span>super text</span>
// <span>regular text</span>
const page = PageObject.create({
spansContain: PageObject.contains('span', { multiple: true })
});
// all spans contain 'text'
assert.ok(page.spanContains('text'));
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>
const page = PageObject.create({
spanContains: PageObject.contains('span', { scope: '.scope' })
});
assert.notOk(page.spanContains('lorem'));
assert.ok(page.spanContains('ipsum'));
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>
const page = PageObject.create({
scope: '.scope',
spanContains: PageObject.contains('span')
});
assert.notOk(page.spanContains('lorem'));
assert.ok(page.spanContains('ipsum'));
- Throws any Will throw an error if no element matches selector
- Throws any Will throw an error if multiple elements are matched by selector and multiple option is not set
Returns Descriptor