Loop with check Element attribut value

Hello,
I have a problem with a piece of code and I need help :slight_smile:

Here is my code :

${elements}= Get WebElements //div[1]/inotr-bloc-annonce
FOR ${element} IN @{elements}
Log ${element}
Element Attribute Value Should Be ${element} data-transaction VENTE
END

My goal is to verify that “data-transaction” attribute can have either “VENTE” value or “XX” value or “YY” value.
I try to insert a “OR” condition inside de “FOR” loop but it doesn’t work.

Thanks for your help !

Hi John,

How about this approach using List Should Contain Value:

    @{ValidDataTransactions}=    Create List    VENTE    XX    YY
    ${DataTransaction}=    Get Element Attribute    ${element}     data-transaction
    List Should Contain Value    @{ValidDataTransactions}    ${DataTransaction}

Dave.

Hi Dave,

Thanks for your answer.
Do you mean an approach like this :

@{ValidDataTransactions}=    Create List    VENTE    XX     YY
    ${elements}=    Get WebElements    //div[1]/inotr-bloc-annonce
    FOR  ${element}  IN  @{elements}
        Log  ${element}
        ${DataTransaction}=    Get Element Attribute    ${element}    data-transaction  
        List Should Contain Value    @{ValidDataTransactions}    ${DataTransaction}    
    END

I try it but I have an error (Keyword ‘Collections.List Should Contain Value’ expected 2 to 3 arguments, got 4.). Perhaps I have a bad construction of my code ?

Hi John,

Yeah that’s the idea, try changing the @ to a $ on the List Should Contain Value line:

List Should Contain Value    ${ValidDataTransactions}    ${DataTransaction}

Sometimes RF wants it one way and sometimes the other, i’m never really quite sure, I just try it and if I get an error I try the other way, same thing with dictionaries (swap & and $).

Dave.

1 Like

You’re alright. I’ve already seen this kind of “problem” but I forgot…
Indeed, the result is now correct :slight_smile:
Thanks a lot !

A last question : do you know why I have a warning near the “List Should Contain Value” line saying : Keyword “List Should Contain Value” is from a library nested a resource file ?

Hi John,

List Should Contain Value comes from the Collections Library, you should include:

*** Settings ***
Library 	Collections

in your robot file, it must be in another robot file that you included in this robot file so that’s how it’s picking it up, but giving you a warning because it’s not in this robot file.

when ever you use a keyword that is not from the builtin library, you should add that library to your robot file.

Dave.

Ok, I thought that when I use Standard Librairies, It’s useless to put it on “Settings” section.
Thanks to you, I know that it’s usefull only for keywords which are not in “BuiltIn” library !

Thanks again :slight_smile: