-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] .$
and .$$
for locators?
#15044
Comments
Could you provide us examples how these functions should behave? Its not very clear to me. Seems a bit related to #12336? |
These function should behave like
Exactly! Examples: element.$ForLocator('sel').click();
// Is equivalent to
element.locator('sel').nth(0).click();
element.$$ForLocator('li').click();
// Compile error. No click function found on a list of locators. Use `nth` or `$ForLocator` to select a child. |
We strongly recommend to use Locators and avoid methods which accept an "unpredictable" amount of elements to reduce flakiness. Thats why I think introducing another method which "works fine" when there are more than 1 element on the DOM would be confusing and go into the opposite direction as we want to. Imagine the scenario, that sometimes there are two elements, and your proposed method would just click the first element on the page. Locators on the other side would throw and the user would directly know that its unexpected instead of clicking on the wrong element. |
That makes sense. Tho it might introduce some |
I'm migrating a playwright codebase using
ElementHandle
to locators. I really miss the$
and$$
. I found locator code tends to be longer and also requires you to pay a bit more attention not to fall into runtime errors.Some examples:
Would it be possible to add 2 helper functions like
.locate$
and.locate$$
for locators? thanks!The text was updated successfully, but these errors were encountered: