Extract data from CSV

Hello,

Do you have an idea of how can I extract several data from CSV (all the column contain for example) ?
Indeed, this column contains URL and I would compare the in URL and be sure that there isn’t redirection.

I imagine that I must extract all the URLs on a dictionnary and use a “FOR” loop for each URL but … i don’t know how open and extract the data :slight_smile:

Thanks a lot

John.

Hi John,

I accidentally answered in Slack which doesn’t post back to the forum

Have you looked at the examples available on the Web? e.g. robotframework read csv file - Google Search. There are some videos as well.

Strangely, I didn’t notice the CSV library in the resources list on RF web page: Robot Framework, so I don’t know if it is recommended, but there is at least one out there mentioned in the search above, as well as example code to read the files yourself. We use the RF DataDriver to pull testcase parameters out of CSV files, but that is row by row.

Hi Kevin,

I’m going to check your proposal !
I think that i could find my hapiness :smiley:

I’ll be back once I found the solution !

Thanks

Hi,

I have found the solution !

Here is my code :

Read CSV file

    ${csv}=    Get File    ${CURDIR}${/}CSV/read_csv_file_inotr.csv

    @{read}=    Create List    ${csv}

    @{lines}=    Split To Lines    @{read}    1

    FOR    ${line_csv}    IN    @{lines}

        Log To Console    \n${line_csv}

        Open Browser     ${line_csv}    chrome

        ${locationURL}=    Get Location

        Should Be Equal    ${line_csv}    ${locationURL}

        Log To Console    Les URLs d'entrée et de sortie sont identiques pour l'URL ${line_csv}

    END

I have another problem but I would describe it on another post !

Thanks a lot.

John

This is the code that successfully worked for me, it involved importing the RPA.Tables library and utilizing the Read Table from CSV keyword.

Library RPA.Tables

Read CSV File
${csv_data}= Read table from CSV path=path/to/your/csv_file
FOR ${csv_row} IN @{csv_data}
Log To Console ${csv_row}
END

2 Likes

I’m using the CSVLibrary for this kind of need.
Checks:

Simple and powerful.

1 Like