Queries
Retrieve values from elements
.attribute
Returns the value of a element’s attribute.
Attribute signature
PageObject.attribute(attributeName, selector [, scope: ''])
Example
<img class="img" alt="Logo" src="...">
var page = PageObject.create({
imageAlternateText: PageObject.attribute('alt', '.img')
});
assert.equal(page.imageAlternateText(), 'Logo');
.count
Returns the count of elements that match the css selector.
Attribute signature
PageObject.count(selector [, scope: ''])
Example
<img class="img" src="...">
<img class="img" src="...">
var page = PageObject.create({
imageCount: PageObject.count('.img')
});
assert.equal(page.imageCount(), 2);
.text
Returns the inner text of the element. Note that whitespace from the beginning and end of the string is removed for convenience.
Attribute signature
PageObject.text(selector [, scope: ''])
Example
<h1>Page title</h1>
var page = PageObject.create({
title: PageObject.text('h1')
});
assert.equal(page.title(), 'Page title');
.textList
Returns the inner text of all elements matched by the provided selector. The result is returned as a list.
Attribute signature
PageObject.textList(selector [, scope: ''])
Example
<ul>
<li>John</li>
<li>Jane</li>
</ul>
var page = PageObject.create({
userNameList: PageObject.textList('li')
});
assert.equal(page.userNameList()[0], 'John');
.value
Returns the value of an input.
Attribute signature
PageObject.value(selector [, scope: ''])
Example
<input id="name" value="John Doe" />
var page = PageObject.create({
name: PageObject.value('#name')
});
assert.equal(page.name(), 'John Doe');