Find element by text (content)
See original GitHub issueIs there a built-in locator to find an element by its html content?
This is for example the xpath expression to locate any element containing the string “You have successfully signed up!”
by.xpath("//*[contains(text(),'You have successfully signed up!')]");
I wonder if there is a nicer DSL for this, e.g.
by.text('You have successfully signed up!');
Or see an example of how to write this with Protractor.By.addLocator
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to get element by innerText - javascript - Stack Overflow
Use document.getElementsByInnerText() to get multiple elements (multiple elements might have the same exact text), and use document.
Read more >Find Element by Content using JavaScript | bobbyhadz
To find elements by content, use the `document.querySelectorAll` method to select dom elements by tag. Then, use the `for...of` loop to iterate over...
Read more >How to Find Element by Text in Selenium: Tutorial
Launch the Chrome browser · Navigate to BrowserStack's website · Locate the CTA with the text value 'Get started free' using the XPath...
Read more >Selenium Find Element By Text Tutorial with Examples
Selenium Find element by text is used to locate a web element using its text value. The text value is generally used when...
Read more >How To Find Element By Text In Selenium WebDriver
The 'findElement' method returns a WebElement object. This object has a 'getText' method, which returns the visible text on that element. To ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was mislead by this issue… currently correct answer seems to be:
https://angular.github.io/protractor/#/api?view=ProtractorBy.prototype.cssContainingText
Hi guys, somebody knows how declare locators for this case: