In Testing, it is essential to understand how to interact with the browser and locate the DOM elements. It is quite easy to handle dropdowns with Robot Framework. In this blog, we will learn about how to handle dropdowns using the Selenium library.
To handle dropdowns there are a few commands provided by the selenium library which are dependent on DOM element Index, Value, and Label.
In this blog, we will discuss-
- Project setup for Drop-down
- Verify drop-downs
- Select index/value/label from drop-downs
Project setup for textbox:
Firstly, we must install all prerequisite libraries in our project (for more info about prerequisites you can visit- https://www.neovasolutions.com/2022/07/21/robot-framework-automation-using-selenium-and-python/ )
After this, we can check our libraries by pip list command, or we can check manually also
File > settings > project: robot-automation > python interpreter

After verifying the prerequisite part create a file dropdown .robot in the TestCases directory.
— go to the new file > give a name of with .robot >Enter


Keywords:
- Get List Items – Returns all labels or values of selection list locator.
- Get Selected List Label – Returns the label of selected option from selection list locator.
- Get Selected List Value – Returns the value of selected option from selection list locator.
- Select From List By Index – Selects options from selection list locator by indexes.
- Select From List By Label – Selects options from selection list locator by labels.
- Select From List By Value – Selects options from selection list locator by values.
- Select All From List – Selects all options from multi-selection list locator.
- Get Selected List Labels – Returns labels of selected options from selection list locator.
- Get Selected List Values – Returns values of selected options from selection list locator.
- Unselect From List By Index – Unselects options from selection list locator by indexes.
- Unselect From List By Label – Unselects options from selection list locator by labels.
- Unselect From List By Value – Unselects options from selection list locator by values.
- Unselect All From List – Unselects all options from multi-selection list locator.
- List Selection Should Be – Verifies selection list locator has expected options selected.
- List Should Have No Selections – Verifies selection list locator has no options selected.
- Page Should Contain List – Verifies selection list locator is found from current page.
- Page Should Not Contain List – Verifies selection list locator is not found on current page.
Now let us write a test case for better understanding with dropdown Keywords.
Testcase:
Step1: Go to https://demo.automationtesting.in/Register.html
Step2: Collect the specific locator for skills dropdown from DOM
Step3: Select the dropdown element by Label ‘c’
Step4: Select the dropdown element by Index ‘4’
Step5: verify element value in list ‘Android’
Step6: Select the dropdown element by Value ‘Installation’
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${browser} chrome
${url} http://demo.automationtesting.in/Register.html
*** Test Cases ***
Handling DropDowns and List
open browser ${url} ${browser}
maximize browser window
select from list by label Skills C
select from list by index Skills 4
List Selection Should Be Skills Android
select from list by value Skills Installation
close browser
*** Keywords ***
***Settings*** – To work with robot framework keywords we need to import the selenium library in the settings section because all these keywords are built in the selenium library-
Library SeleniumLibrary
Similarly, we can import other libraries, resource files, and variable files as per our project requirement in this section.
***Variables***– This section contains the defined variables that are used commonly, here we have declared variables of browser and URL so we can reuse these variables.
${url} ${browser}
in the same way, we can create more variables like this according to the requirement of the project.
***Test Cases***-

Code Explanation:
The first step in this test is to open the URL https://demo.automationtesting.in/Register.html in Chrome. Then we select the ‘C’ option from the dropdown using
Select From List By Label Skills C
In this command, we are selecting by the label of the dropdown.
Similarly, the index command works in this its based on the index number of list elements.
Select From List By Index Skills 4
In this case, we are providing index number 4, which will result in the selection of ‘Android’
To verify that the selected dropdown by index number is Android or not here we are using another keyword
List Selection Should Be Skills Android
It verifies that the selected dropdown value is correct.
Same as like select from the list by label and select from the list by index we can also use –
Select From List By Value Skills Installation
The value we can get from the DOM section of the dropdown this command will select the same value we provided as a value.
Finally, we are using close browser to close the browser and end the test.
Execution:
To execute the test case we need to use the command on the terminal:

After execution, we should get the result as a pass.

Report:


Conclusion-
In this Blog, we learned how to interact with the dropdowns using the Selenium library in the Robot Framework. With the keywords provided by the robot framework and the library imported, we can do actions with dropdowns and verify them as well.
Read our next blog on “How to handle alerts in Robot Framework”.