# Loop with check Element attribut value

**URL:** <https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220>\
**Category:** Robot Framework\
**Created:** [3 August 2021 09:21 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220 "2021-08-03T09:21:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [3 August 2021 09:21 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/1 "2021-08-03T09:21:22Z")

</div>

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

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 !

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [3 August 2021 10:09 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/2 "2021-08-03T10:09:59Z")

</div>

Hi John,

How about this approach using [List Should Contain Value](http://robotframework.org/robotframework/latest/libraries/Collections.html#List%20Should%20Contain%20Value):

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

```

Dave.

---

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [3 August 2021 12:29 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/3 "2021-08-03T12:29:07Z")

</div>

> [@Centaure13](#):
>
> ${elements}= Get WebElements //div[1]/inotr-bloc-annonce

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 ?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [3 August 2021 12:34 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/4 "2021-08-03T12:34:44Z")

</div>

Hi John,

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

```python
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.

---

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [3 August 2021 12:43 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/5 "2021-08-03T12:43:31Z")

</div>

You’re alright. I’ve already seen this kind of “problem” but I forgot…  
Indeed, the result is now correct 🙂  
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_ ?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [3 August 2021 12:50 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/6 "2021-08-03T12:50:52Z")

</div>

Hi John,

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

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

---

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [3 August 2021 12:58 UTC](https://forum.robotframework.org/t/loop-with-check-element-attribut-value/2220/7 "2021-08-03T12:58:48Z")

</div>

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 🙂
