externalBy
Index
Constructors
Methods
Constructors
externalconstructor
Returns By
Methods
staticexternalcss
Locates a
PageElementusing a CSS selector.Parameters
externalselector: Answerable<string>
Returns Question<Promise<ByCss>>
staticexternalcssContainingText
Locates a
PageElementwith a giveninnerTextusing a CSS selector.Parameters
externalselector: Answerable<string>
externaltext: Answerable<string>
Returns Question<Promise<ByCssContainingText>>
staticexternaldeepCss
Locates a
PageElementusing a CSS selector capable of piercing shadow DOM-piercingParameters
externalselector: Answerable<string>
Returns Question<Promise<ByCss>>
staticexternalid
Locates a
PageElementusing its id.Parameters
externalselector: Answerable<string>
Returns Question<Promise<ById>>
staticexternalrole
Locates a
PageElementby its ARIA role, ARIA attributes and accessible name.Example usage
Given the following HTML structure:
<h3>Sign up</h3>
<label>
<input type="checkbox" /> Subscribe
</label>
<br/>
<button>Submit</button>Each element can be located by its implicit accessibility role:
const heading = PageElement.located(By.role('heading', { name: 'Sign up' })).describedAs('Sign up heading');
const checkbox = PageElement.located(By.role('checkbox', { name: 'Subscribe' })).describedAs('Subscribe checkbox');
const button = PageElement.located(By.role('button', { name: 'Submit' })).describedAs('Submit button');Playwright Test
import { Ensure } from '@serenity-js/assertions'
import { Click, PageElement, By, isVisible } from '@serenity-js/web'
// ... page element definitions as above
describe('ARIA role selector', () => {
it('locates an element by its accessible name', async ({ actor }) => {
await actor.attemptsTo(
Ensure.that(heading, isVisible()),
Click.on(checkbox),
Click.on(button),
)
})
})WebdriverIO
import { actorCalled } from '@serenity-js/core'
import { Ensure } from '@serenity-js/assertions'
import { Click, PageElement, By, isVisible } from '@serenity-js/web'
// ... page element definitions as above
describe('ARIA role selector', () => {
it('locates an element by its accessible name', async () => {
await actorCalled('Nick').attemptsTo(
Ensure.that(heading, isVisible()),
Click.on(checkbox),
Click.on(button),
)
})
})Parameters
externalrole: ByRoleSelectorValue
externaloptions: Answerable<{ checked?: Answerable<false> | Answerable<true>; disabled?: Answerable<false> | Answerable<true>; exact?: Answerable<false> | Answerable<true>; expanded?: Answerable<false> | Answerable<true>; includeHidden?: Answerable<false> | Answerable<true>; level?: Answerable<number>; name?: Answerable<string> | { flags: Answerable<string>; sticky: Answerable<false> | Answerable<true>; unicode: Answerable<false> | Answerable<true>; [match]: any; [replace]: any; [search]: any; [split]: any; dotAll: Answerable<false> | Answerable<true>; [matchAll]: any; hasIndices: Answerable<false> | Answerable<true>; exec: any; test: any; source: Answerable<string>; global: Answerable<false> | Answerable<true>; ignoreCase: Answerable<false> | Answerable<true>; multiline: Answerable<false> | Answerable<true>; lastIndex: Answerable<number>; compile: any }; pressed?: Answerable<false> | Answerable<true>; selected?: Answerable<false> | Answerable<true> }> = {}
Returns Question<Promise<ByRole>>
staticexternaltagName
Locates a
PageElementusing the name of its HTML tag.Parameters
externalselector: Answerable<string>
Returns Question<Promise<ByTagName>>
staticexternalxpath
Locates a
PageElementusing an XPath selector.Parameters
externalselector: Answerable<string>
Returns Question<Promise<ByXPath>>
Byproduces aSelectorused to locate aPageElementorPageElementon a web page. Selectors can be defined using a static value or aQuestionto be resolved at runtime.Defining a selector using a string
Every selector method on this class accepts a static
stringvalue to define a selector.Defining a selector using a Question
Each method on this class also accepts an
Answerableto allow for dynamic resolution of the selector. This can be useful when the selector is not known at the time of writing the test, or when the selector needs to be calculated based on the state of the system under test.The example below demonstrates how to use
qto define a selector that includes a dynamic value.Learn more
PageElementPageElementq