Robotframework : How check if a text is present in EACH element

Hello,

I’m new in Robotframework and I have an issue with my test in RobotFramework.

On a page, there are many element with this locator :
//*[@class=“resultats mode_liste ng-scope”]/div[@ng-repeat="annonce in resultats.data.annonces "]//h2/a/strong[1][@class=“ng-binding”]

Example of structure :

  • A “div” element contains “locator1” which contains “House”
  • A “div” element contains “locator1” which contains “House”
  • A “div” element contains “locator1” which contains “Box”

In my test, I want to check that each element contains, for example, the word “House”.
I have tried to do this :
Element Should Contain //*[@class=“resultats mode_liste ng-scope”]/div[@ng-repeat="annonce in resultats.data.annonces "]//h2/a/strong[2][@class=“ng-binding”] Box

But the robot check only the first element with this locator. And I want to check that the word “Box” is present in EACH element with this locator.
The result is not what I expected (error if another word than “House” is founded on the locator1)

Any idea?

Thanks a lot !

Get WebElements keyword will return you a list that has all the elements returned by your selector. You can then loop thru the elements with for loop and check that each element has appropriate properties…

Thank you for your help.
The “Get WebElements” keyword was the solution. But I have to code a little bit to adapt my request like that =>

{elements}= Get WebElements //*[@class="resultats mode_liste ng-scope"]/div[@ng-repeat="annonce in resultats.data.annonces "]//h2/a/strong[2][@class="ng-binding"] FOR {element} IN @{elements}
Log {element.text} Element Should Contain {element} House
END

Thanks again :slight_smile: