Rayrun
← Back to Discord Forum

Is it possible to pass incomplete strings into a locator?

I'm thinking something like page.locator(startsWith(#button--listbox-input)).click()

This thread is trying to answer question "Is it possible to pass incomplete strings into a locator?"

5 replies
@adamdelsol: And for comparison, the "complete" string would look like... ?

And for comparison, the "complete" string would look like... ?

#button--listbox-input--19

But the 19 is dynamic.

So the first part of the element id is static and it's differentiated enough from the other elements on the page that it would be great if I could just use that for the time being until I have time to implement static test-ids

you'll need to use css selector, for example page.locator('[id^=button--listbox-input]') will match all elements that start with button--listbox-input

@skorp32: That worked. Thanks so much!

That worked. Thanks so much!

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].