Verify if a word belong to a list

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.

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

@{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

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 :slight_smile:

Just change that to:

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