Interact with Dropdown elements using data driven testing in robot framework

I’m currently implemenating Robot Framework for a web application testing. I need to interact with few dropdown elements. I want to save dropdowndown elements options in a CSV/Excel file. and then use one of the option in the testcase using that CSV/Excel file. I’m using selenium library and pycharm IDE.

for example, in below code i want to click an dropdown element and select a particular option. but i want to save that option inside a CSV file and call it in my testcase instead of hard coding.

Click Element //select[@id=‘plantSelector’]
Click Element //option[@value=‘52’]

I have already installed datadriver library and csv library. I tried the below block of code and multiple other options. but so far no success.

Any help would be appreciated. Need a starting point.

Hi Vinay,

This is a good example of where creating your own keywords can be useful. You can create a keyword like this:

*** Keywords ***
Select Option By Value
    [Arguments]     ${selid}    ${value}
    Click Element //select[@id=‘${selid}’]
    Click Element //option[@value=‘${value}’]

Then in your test case you can replace those two lines with

    Select Option By Value    plantSelector    52

changing the values as needed or even replacing them with the variables you extracted from the CSV

Hope that helps,

Dave.

1 Like

Hi Dave,
Thanks for the reply.
However, I do not want to declare the value that is ‘52’ inside my test case. I want to only pick the value from the Excel/CSV without declaring it in my test case. and if i want to change that value ‘52’ to something else then i would change that in the excel/CSV file instead of declaring it in my test case.

another example scenario.

in above testing website, there’s a dropdown element ‘Continents’ which has different continenents in drop down.

Asia
Europe
Australia
Africa
South America
North America
Antartica.

So my goal is to save only 1 option which is ‘Asia’ from the list of continents in an excel/CSV and then call that option during my test case. eg. Click Element and then Click the option which is ‘Asia’.
And if i want to pick a different continent then i would only change the value in my testdata file instead changing it directly inside my testcase.

I hope this clarifies what i’m looking for.

Thanks again.

As I mentioned you can replace the 52 with any variable you like, e.g.:

    Select Option By Value    ${your_plantSelector_variable)    ${your_52_variable}

You didn’t say which Library/keywords you are using for reading the excel/CSV files, have you worked that out yet? You define the variable when you use the keyword that reads the file, then you pass that value to the next keyword that interacts with the web site.

In that above testing website, the dropdown element ‘Continents’ is an option list, so you can use the “List” keywords with it.

I’ll leave you to play and learn how to drive that “AUTOMATION PRACTICE FORM” as it looks like a good practice form :+1:

Dave.

1 Like

Just to help with choosing a library for Excel, from the many I have played with this is a solid choice, see below links:

https://rawgit.com/peterservice-rnd/robotframework-excellib/master/docs/ExcelLibrary.html

definitely many more out there but some are more limiting than others, please look at the supporting file type when choosing to save any headache.