Attribute
Returns the value of the given HTML attribute of a given WebElement, represented by Answerable<Element>
Extends:
Question → Attribute
Implements:
Examples:
Example widget
<ul id="shopping-list" data-items-left="2">
<li data-state="bought">Coffee<li>
<li data-state="buy">Honey<li>
<li data-state="buy">Chocolate<li>
</ul>
Retrieve a HTML attribute of a given WebElement
import { actorCalled } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
import { Attribute, by, BrowseTheWeb, Target } from '@serenity-js/webdriverio';
const shoppingList = () =>
Target.the('shopping list').located(by.id('shopping-list'))
actorCalled('Lisa')
.whoCan(BrowseTheWeb.using(browser))
.attemptsTo(
Ensure.that(Attribute.called('data-items-left').of(shoppingList()), equals('2')),
)
Find WebElements with a given attribute
import { actorCalled } from '@serenity-js/core';
import { Ensure, includes } from '@serenity-js/assertions';
import { Attribute, BrowseTheWeb, by, Target } from '@serenity-js/webdriverio';
class ShoppingList {
static items = () =>
Target.all('items')
.located(by.css('#shopping-list li'))
static outstandingItems = () =>
ShoppingList.items
.where(Attribute.called('data-state'), includes('buy'))
}
actorCalled('Lisa')
.whoCan(BrowseTheWeb.using(browser))
.attemptsTo(
Ensure.that(
Text.ofAll(ShoppingList.outstandingItems()),
equals([ 'Honey', 'Chocolate' ])
),
)
Static Method Summary
Static Public Methods | ||
public static |
|
Constructor Summary
Public Constructor | ||
public |
constructor(name: Answerable<string>, element: Answerable<Element<'async'>>) |
Method Summary
Public Methods | ||
public |
async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise |
|
public |
Resolves to the value of a HTML attribute of the |
Static Public Methods
Public Constructors
Public Methods
public async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise source
Params:
Name | Type | Attribute | Description |
actor | AnswersQuestions & UsesAbilities |
Returns:
Promise |