Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium: test if element contains some text

Tags:

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)
like image 450
Mark W Avatar asked Mar 29 '12 08:03

Mark W


People also ask

How do you know if a Webelement contains text?

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.

How do I find the partial text of an element?

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.

How do I find an element that contains specific text in Selenium Webdriver Python?

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.


1 Answers

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*.

like image 154
Petr Janeček Avatar answered Sep 22 '22 17:09

Petr Janeček