# Verify if a word belong to a list

**URL:** <https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894>\
**Category:** Robot Framework\
**Created:** [2 December 2021 10:44 UTC](https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894 "2021-12-02T10:44:36Z")\
**Posts on this page:** 4\
**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:** [2 December 2021 10:44 UTC](https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894/1 "2021-12-02T10:44:36Z")

</div>

Hello,

I have a page with a list of link which contains all french department like :

- prix immobilier Var
- prix immobilier Bouches-du-Rhône
- etc…

I would like to verify for each link that the link contains the french departement.  
I thought to create a list of departement first like `@{list_dpt}= Var Bouches-du-Rhône` … (it’s very long but I haven’t other solution).

Here is the piece of code :

```
FOR ${element} IN @{elements}
        ${nomAncre}= Get Text //div[@class="immobilier-liste-liens"]/ul/li    
        ${dpt}= Get Substring ${nomAncre} 16 //(to keep only the name of the department)

```

But after, I don’t know how I can check that each link must contain a department from the list

Thanks a lot

John.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 10:57 UTC](https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894/2 "2021-12-02T10:57:17Z")

</div>

To check if a value is in a list we use the operator `in` . So, for example your code could be:

```python
@{list_dpt}= Create List Var Bouches-du-Rhône …
@{results}= Create List
FOR ${element} IN @{elements}
        ${nomAncre}= Get Text //div[@class="immobilier-liste-liens"]/ul/li    
        ${dpt}= Get Substring ${nomAncre} 16 //(to keep only the name of the department)
        IF ${dpt} in ${list_dpt}
            Append to List ${results} "${dpt} is OK"
       ELSE
           Append to List ${results} "${dpt} is NOT OK"
       END
END

```

---

<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:** [2 December 2021 12:57 UTC](https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894/3 "2021-12-02T12:57:08Z")

</div>

Hello,

Thank you for your help !  
Unfortunatly, I’m on RF 3.2.2 (not 4.x because I encountered many problems when I tried to install this version)) so the “IF” statement is not supported on RF 3.2.2.  
Have you a similar proposal adapted to my configuration ?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [2 December 2021 13:00 UTC](https://forum.robotframework.org/t/verify-if-a-word-belong-to-a-list/2894/4 "2021-12-02T13:00:41Z")

</div>

> [@HelioGuilherme66](#):
>
> ```python
> IF ${dpt} in ${list_dpt}
> Append to List ${results} "${dpt} is OK"
> ELSE
> Append to List ${results} "${dpt} is NOT OK"
> END
> 
> ```

Just change that to:

```python
        ${row}= Set Variable If ${dpt} in ${list_dpt} "${dpt} is OK" "${dpt} is NOT OK"
        Append to List ${results} ${row}

```
