playwright
playwright copied to clipboard
Provide an alternate way of locating an element in codegen
When testing content from a CMS the content is constantly changing, so we can't rely on the text of an element.
Eg : Test clicking on the first search results .. but codegen only give me something like:
await page.getByRole('link', { name: 'Blue carbon futures' }).click();
It would be great if it gave me the best practice way of finding the first item in the list so that can be clicked on eg:
await page.locator(".search_results > li > a ").first().click();
Is there any chance it can be be put into a 'no text match' mode where it relies on class names and dom element relationships instead of matching text that can (and often does) change?
Thanks
I agree, but there are many different ways to locate an element. How should we give hints to Playwright which to choose? I think one option is to offer alternatives:
- When "Pick Locator" manually, on the VSCode dropdown Playwright should offer some variations to choose which one to copy.
- When "Recording" a test, Playwright could add some other variations to each step as comments.