playwright icon indicating copy to clipboard operation
playwright copied to clipboard

Provide an alternate way of locating an element in codegen

Open wolispace opened this issue 1 year ago • 1 comments

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

wolispace avatar Oct 31 '23 06:10 wolispace

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:

  1. When "Pick Locator" manually, on the VSCode dropdown Playwright should offer some variations to choose which one to copy.
  2. When "Recording" a test, Playwright could add some other variations to each step as comments.

rlaci999 avatar Nov 26 '23 11:11 rlaci999