grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
342 stars 42 forks source link

Implement text selectors #101

Open robingustafsson opened 2 years ago

robingustafsson commented 2 years ago

Add support for querying the DOM using text selectors, looking for element(s) based on text that is shown to end-users as part of presenting element(s), eg. page.click('text=Log in');, regex based page.click('text=/Log\\s*in/i'); or simply page.click('"Log in"');

Supporting text based selectors are important from the perspective of test stability, it's a way to specify "non-flaky" selectors that match on the text of an element rather than it's DOM specifics (element type or location in DOM).

Relevant links:

imiric commented 2 years ago

Just to point out that until this is implemented, it can be worked around with XPath selectors and text(), e.g. //button[text()="Submit"].

eugercek commented 1 year ago

Hi, I would like to work on the issue if it's ok.