Skip to content

Using an attribute value from one element locator as a dependency to another locator #2412

Answered by jan-molak
bhreinb asked this question in How to... ?
Discussion options

You must be logged in to vote

Sure, the way you want to approach it makes perfect sense.

Here's how you can do it step by step.

Getting all the labels

import { PageElements, By } from '@serenity-js/web'

const labels = () =>
  PageElements.located(By.css('[data-automation-id="formLabel"]'))
    .describedAs('labels')

Getting a label by its text content

import { PageElements, By, Text } from '@serenity-js/web'
import { includes } from '@serenity-js/assertions'

const labels = () =>
  PageElements.located(By.css('[data-automation-id="formLabel"]'))
    .describedAs('labels')
    
const labelCalled = (name: string) => 
  labels()
    .where(Text, includes(name))
    .first()

Getting and attribute

import { Attribute, Page…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@bhreinb
Comment options

@jan-molak
Comment options

Answer selected by jan-molak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@serenity-js/web Screenplay Pattern APIs for interacting with the Web
2 participants