# Interact with Dropdown elements using data driven testing in robot framework

**URL:** <https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222>\
**Category:** Robot Framework\
**Created:** [15 September 2023 19:11 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222 "2023-09-15T19:11:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinayrana](https://avatars.discourse-cdn.com/v4/letter/v/7ab992/32.png) [@vinayrana](https://forum.robotframework.org/u/vinayrana)\
**Post date:** [15 September 2023 19:11 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222/1 "2023-09-15T19:11:34Z")

</div>

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.

---

<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:** [16 September 2023 00:09 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222/2 "2023-09-16T00:09:41Z")

</div>

Hi Vinay,

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

```plaintext
***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

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

---

<div class="post-metadata">

**Author:** ![vinayrana](https://avatars.discourse-cdn.com/v4/letter/v/7ab992/32.png) [@vinayrana](https://forum.robotframework.org/u/vinayrana)\
**Post date:** [17 September 2023 17:02 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222/3 "2023-09-17T17:02:44Z")

</div>

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.

> **[Demo Automation Practice Form](https://www.techlistic.com/p/selenium-practice-form.html)**
>
> This is a demo selenium webpage to practice web form actions. It contains all basic form components on which selenium beginners can practice selenium commands.

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.

---

<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:** [19 September 2023 08:49 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222/4 "2023-09-19T08:49:47Z")

</div>

> [@vinayrana](#):
>
> 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.

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

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

Dave.

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [19 September 2023 15:47 UTC](https://forum.robotframework.org/t/interact-with-dropdown-elements-using-data-driven-testing-in-robot-framework/6222/5 "2023-09-19T15:47:56Z")

</div>

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

> **[robotframework-excellib](https://pypi.org/project/robotframework-excellib/)**
>
> Robot Framework library for working with Excel documents

> **[GitHub - peterservice-rnd/robotframework-excellib: Robot Framework library...](https://github.com/peterservice-rnd/robotframework-excellib)**
>
> Robot Framework library for working with Excel documents. - GitHub - peterservice-rnd/robotframework-excellib: Robot Framework library for working with Excel documents.

[https://rawgit.com/peterservice-rnd/robotframework-excellib/master/docs/ExcelLibrary.html](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.
