Rayrun
โ† Back to Discord Forum

chaining the locators

Hi, I have a scenario where there are a list of users who are active and inactive. There is a tag which let people know who are active and who are not. If I want to go the detail of the user, there is a icon which can take me there. Based on these scenarios, I have to select a active user and open it's details page.

I was wondering if there is something like, Page.locator(activeTagVariable).first().locator(detailIconLocatorVariable).click().

This is something I want to achieve, but I am failing. Is there any way to do so?

This thread is trying to answer question "Is there a way to chain locators in Playwright to select an active user and open its details page?"

16 replies

you can do locator(string|Locator) only with FrameLocator otherwise you will need the detailIconLocatorVariable in string type

.aleksandaraleksandrov
.aleksandaraleksandrov

https://playwright.dev/docs/locators look for chaining locators on this page ๐Ÿ™‚

tester_65313

Hi everyone, Can anyone tell, is playwright supports chaining in action methods, like await page.locator.click().clear().type()

@tester_65313: Nope you have to write steps separately

Nope you have to write steps separately

@tester_65313: You can write your own api with chain approach ๐Ÿ™‚

You can write your own api with chain approach ๐Ÿ™‚

tester_65313
@bububu8615: thanks for the response

thanks for the response

tester_65313
@marble_95: could you guide us by providing sample code

could you guide us by providing sample code

@tester_65313: Sure, give me some time to prepare it

Sure, give me some time to prepare it

tester_65313
@marble_95: Sure marble, take your time

Sure marble, take your time

@tester_65313: check it out here https://oholsyhevskyi.com/posts/chained-functions-in-test
tester_65313

thanks @marble_95 for helping

@tester_65313: does it work?

does it work?

tester_65313

im working with Javascript, getting errors

tester_65313

could you write for js

@tester_65313: it's time to switch on TS ๐Ÿ˜‰ https://transform.tools/typescript-to-javascript

it's time to switch on TS ๐Ÿ˜‰ https://transform.tools/typescript-to-javascript

tester_65313

thanks @marble_95

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 luc@ray.run.