With Selenium IDE, how can I test if an element's inner text contains a specific string? For example:
<p id="fred">abcde</p>
'id=fred' contains "bcd" = true)
There are more than one ways to find it. We can use the getPageSource() method to fetch the full page source and then verify if the text exists there. This method returns content in the form of string. We can also check if some text exists with the help of findElements method with xpath locator.
Find element by text is used to locate a web element using its text value. Predefined method text() is used to achieve the same. Contains method is used to find web elements with partial text match. Text method is used to identify a web element uniquely using the property text.
We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element. The function text() in xpath is used to locate a webelement depending on the text visible on the page.
The Selenium-IDE documentation is helpful in this situation.
The command you are looking for is assertText
, the locator would be id=fred
and the text for example *bcd*
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With