-
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] A special locator to visually locate an element #2877
Comments
Have you seen already the selector documentation? Text, css, xpath, shadow dom selectors are available: https://playwright.dev/#version=v1.2.0&path=docs%2Fselectors.md&q= Does this fit for your needs? A feature for highlighting a certain dom node will be tracked here: #2747 |
Yes, I have seen it and it still doesn't fit my need. I would love to see this feature. Last but not least, thanks for a great library. I also saw you python version. Hopefully, we can have a production version soon :) |
@mxschmitt Another use case I can think of is for web scrapping that we need to rely on html structure/attribute if there is no id/data-testid assigned. The maintenance cost for that script will be really high if we need to rely on css/xpath on this case. |
I'd also love to see "proximity selectors" (as the Taiko team calls them) added to the Playwright API. They'd make "black box" testing (i.e. purely from the point of view of the end user w/o any insight into the application's technical details (DOM, CSS, etc.)) become a reality. They've been recently added to Selenium as well, see here. (They call it "relative locators".) For me, they would be most useful in locating/selecting an element via text selector if there are several elements with the same text on a page. Currently, the text selector would simply return the first found element which may not be the one intended to select. With proximity selectors, however, one could much better specify which particular element one is interested in. |
I am currently in the midst of evaluating a handful (4, actually) of E2E test automation tools for my team, among them Taiko and Playwright. I've started with Taiko and my experience so far with those proximity selectors (see link in this thread's initial post) is simply splendid: I can create entire e2e tests in full black-box mode, meaning that I use only information I see on the tested web page w/o having to inspect the page's html code in any way. This makes creating and maintaining e2e tests a real breeze, with pretty low efforts. It's a pure pleasure, really. 👍 @pavelfeldman @mxschmitt @aslushnikov @yury-s @JoelEinbinder If you guys haven't done so yet you really ought to check this out yourselves! :) I am convinced that the day you do this you'll put those proximity selectors on Playwright's roadmap. I hope you take note. |
@pavelfeldman @mxschmitt @aslushnikov @yury-s @JoelEinbinder @arjun27 Given that ThoughtWorks will cease supporting Taiko (I'd say best-in-class regarding smart/proximity selectors) by the end of this year and that from 2021 on Taiko will be a fully community-managed open source project (see here), now would be a good time (re)contemplating about adding such smart selectors to Playwright as well (or, as an interim solution, explain in more detail how Taiko's selector engines can be successfully registered and used in Playwright -- see #3667). Sorry for making such a noise about it, it's just that by my own experience with Taiko it makes creating and maintaining e2e tests a pure joy. |
very great feature, the selenium 4 will implement these friendly selector |
I'm willing to initiate a selector engine that implements relative selectors. I was planning to make use of Playwright's chaining like this. What do you think of this syntax ?
@idxn @roughsoft Do you think relative selectors fits your requirements ? i.e. toLeftOf, toRightOf, above, below, near By the way, I'm Jeff on Playwright's Slack. Feel free to drop me a message there |
@jfgreffier That would be awesome! IMHO the mentioned relative selectors (also called proximity selectors, see for example https://docs.taiko.dev/api/reference/) would perfectly fit the requirements. Regarding the syntax you should have a look at @pavelfeldman's comment in a duplicate issue in which he gives an example for a corresponding syntax. |
@jfgreffier That covers everything I need. |
@jfgreffier If you can implement the relative/proximity selectors, like the ones that Taiko supports, than this would be great. |
@jfgreffier thank you! |
@jfgreffier I would like these: |
Please check the first version of Playwright relative selector ! It allows you to select an element by its relative position to another one It's in early phase. My goal at the moment is to get feedback on it, so don't hesitate to drop an issue here @roughsoft I created an issue to discuss specifically of the syntax jfgreffier/playwright-relative-selector#1 |
@jfgreffier : I looked at your repo, great job! Is there a way to pass selector into the |
@pavelfeldman That was my first approach, to create a custom selector engine. However, I faced some issues:
It's better to don't reinvent the wheel and reusing Playwright selectors is ideal. Do you think there is a workaround or a better way to don't interfere with the auto-wait logic ? |
@pavelfeldman Good news? Will this be included in playwright? |
Will launch in 1.8 |
Let us know what functionality you'd like to see in Playwright and what is your use case.
A special locator to visually locate an element.
In taiko, browser automation library by thoughtwork, you could locate element visually like the following:
click(checkbox(near("Username")))
Taiko calls it proximity locator
Refer: https://docs.taiko.dev/#smart-selectors
This locator will reduce the flakiness of the script and the maintenance cost because the locator doesn't rely on html structure that may be changed from time to time. Even we can assign data-testid attribute but this is very useful in some cases as well.
Do you think others might benefit from this as well?
Yes, it is.
The text was updated successfully, but these errors were encountered: