playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Generate Multiple Selectors for an Element in Debugging Mode

Open xushushun opened this issue 1 year ago • 0 comments

🚀 Feature Request

In debugging mode, executing the command in the browser's developer tools generates a selector for the given element. However, in some cases, the generated selector can be problematic, such as when the element's ID changes dynamically. The selector generation often prioritizes IDs for locating elements, leading to unreliable results when IDs are not static.playwright.selector(element)

Example

Would it be possible to modify the command to generate multiple selectors for an element, ranked by priority? This way, developers could have more reliable options to choose from in scenarios where certain attributes, like IDs, are prone to change.

Motivation

Currently, the command generates a single selector, which can be unreliable when dynamic attributes such as IDs are used. By generating multiple selectors, Playwright would provide more flexibility and reliability for developers, allowing them to select an element using more stable attributes when certain attributes are prone to change. This enhancement would reduce the need for manually adjusting selectors and increase efficiency when dealing with dynamic web pages, ultimately making Playwright more robust in a wider variety of scenarios.playwright.selector(element)

xushushun avatar Oct 10 '24 08:10 xushushun