Closed zac11 closed 1 year ago
@zac11 you can probably (ab)use xpath for this (like in this SO question).
I'll check with the folks if there's some nicer way to do this.
@aslushnikov Playwright has spoiled me in ways that I don't want to use xpath anymore 😆 I'll wait if there is anything we can do with the regex pattern in css locators.
Xpaths are always a last resort ( no offense xpath)
@zac11 you can also use the CSS attribute selectors:
page.locator('css=[class^=testBanner]');
But this is probably the best we can think of!
We can use a regex pattern, in the
page.locator
method to select an element - as mentioned in the example here.I'm looking to see if I can use the same for a class based css locator ? For eg, I have this code block
Can I use something like this
await page.locator('class=testBanner__/[A-Za-z0-9]/i+').click()
Reason - The web page that I'm trying to automate has these classes generated dynamically using the ant-design framework , which keeps changing after some time and makes it hard to generate locators.
Please excuse if the regex pattern is not correct.