Skip to content
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

Selector to find any element by text/partial text? #2333

Closed
peterjwest opened this issue Oct 3, 2017 · 4 comments
Closed

Selector to find any element by text/partial text? #2333

peterjwest opened this issue Oct 3, 2017 · 4 comments

Comments

@peterjwest
Copy link

The problem

I would like to query elements by text or partial text match without a restriction on element type. This is useful in cucumber steps such as /^I click the "(.*)" button$/, where the button could be implemented with an <a>, <button> or <input> tag.

I also may wish to look for text on a page e.g. "You have been logged out", but this could be embedded in almost any element, in which case it is not practical to enumerate all possible tags and search for the text with each one.

From the docs it doesn't look like this is possible without specifying an element type, is there a way? Can there be one?

Environment

  • WebdriverIO version: 4.8.0
  • Node.js version: 6.11.3
  • Standalone mode
@christian-bromann
Copy link
Member

@peterjwest you can try *=some text. If that doesn't work you have to use xpath. There are tutorials on the internet on how to use xpath to query an random element with a specific text. Please join our Gitter for these kind of questions. This is not necessary an issue.

@locofocos
Copy link

This is really high in Google results, so here's a working example:

browser.getText("//*[contains(text(),'Hello')]")

https://stackoverflow.com/a/2994336/4176104

@peterjwest
Copy link
Author

Thanks!

@cbou
Copy link

cbou commented Jan 17, 2019

*=some text is working for me (v4.13.2).

@christian-bromann why were you not sure that it would work? Was it related to the version of Webdriverio used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants