Element Should Contain Multiple Strings

Dear All,

It may have been a question already, tried to search the forums for it, however I was unsuccessful finding a proper solution so far.

I do have a list of individual words that I need to verify on a page, mostly German translations of field labels, if they appear correctly.
I have created a list variable as follows:

@{GERMAN_CLAIMS} | Sparte | Versicherungsbeginn | Rechtsform | Transaktionen | Notiz

Is there a good solution to check and verify all of them at once?
What I tried to do is:

${validate_text} =    Wait Until Keyword Succeeds    6s    2s    Get Text    ${GENERAL_CLAIM_BOARD}
Log    ${validate_text}
Element Should Contain    ${GENERAL_CLAIM_BOARD}    ${GERMAN_CLAIMS}[0]

But then I would need to like replicate the last keyword so many times. I just got the text of a certain container to see what words are on the page.

Is there a way to walk this array from [0] to ? Or is this a bad approach? Or shall I just create a loop around it to check its contents?

Thank you very much!

hum something like :

[Templates with for loops]

If templates are used with [for loops]template is applied for all the steps inside the loop. The continue on failure mode is in use also in this case, which means that all the steps are executed with all the looped elements even if there are failures.

*** Test Cases *** 
Template and for 
    [Template]            Example keyword 
              FOR             ${item}         IN         @{ITEMS}        
                                  ${item}         2nd arg 
              END 
              FOR            ${index}        IN          RANGE            42 
                                 1st arg          ${index} 
              END

found this here

1 Like

@serici Oh, could this be simple as that. Alright, I was thinking in something more complex. But this makes sense. Thank you for that, I missed this somehow.

if all of those words are in one parent element i suggest you to use parametrized xpath locator
eg
{locator} xpath=//div[./div[text()='{}'] and ./div[text()='{}'] and ./div[text()='{}']] {searched _element} String.format {locator} {your_german_word_1} {your_german_word_2} {your_german_word_3}
Wait Until Page Contains ${searched _element}

1 Like

Thank you for this @extr3mal! This seems easier, however could you please clarify this for me a bit? I am trying to understand the code you shared but I am having difficulties.

So this line would look like the following under Variables? (I am using “|” for the spaces):

${locator}= | xpath=//div[./div[text()=‘{}’] and ./div[text()=‘{}’] and ./div[text()=‘{}’]] | ${searched _element}

Is this line a python method and should go to the Keywords section?:

String.format | ${locator} | {your_german_word_1} | {your_german_word_2} | {your_german_word_3}

Thank you very much for the help! :slight_smile:

Variable that contains locator by itself (e.g. xpath=//blahblah) can be inside keyword definition file (e.g. resource file, or in separate file (something like page object))
Second line (e.g. String,Format do something) is a robotframework keyword from String library. so it should be used as a keyword.

Overall you make a complex locator, and include places that are same inside of it (its a div with class that not changed and so on) then using figure brackets {} you insert a dynamic part of a locator (e.g. text that will be changed) then you use string format to insert a dynamic part into static part and get overall locator .

First line should not contain anything except variable and xpath value , searched_element is excessive over there

Overall code is looked like so :
First make a locator with static and dynamic parts
${dynamic_element} xpath=//div[./div[text()=’{}’] and ./div[text()=’{}’] and ./div[text()=’{}’]]
Then inside method call for that locator (arg1,arg2,arg3 are dynamic elements inside locator above
${el}= String.format ${dynamic_element} ${arg1} ${arg2} ${arg3}
Then you search for ${el} because it is formatted locator that should be used