How to handle dropdowns in Robot Framework 

HOME

In this tutorial, we will automate the execution of DropDown in Robot Framework.

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework Selenium Library
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

Implementation Steps:

Step 1.1 – Open PyCharm and create a new project. Go to File and select New Project from the main menu.

Step 1.2 – Choose the project location. Click the “Browse” button next to the Location field and specify the directory for your project.

Deselect the Create a main.py welcome script checkbox because you will create a new Python file for this tutorial.

Click on the “Create” Button.

Step 1.3 – A new dialog appears asking to open the project using any one of the given options. I have selected New Window as I like to have separate windows for each project.

Below is the image of the new project created in PyCharms.

How to create a test to automate the options of dropdown in Robot Framework?

Step 4 – Create a new directory in the new project

Right-Click on the project, select New->Directory and provide name as Tests

Below is the image of the new directory.

Right-click on the new directory and select New File and provide the name as DropDown_Demo.robot as shown below:

Step 5 – Download ChromeBinaries from the below location

The tests are going to use the Chrome browser, so we need to download the ChromeBinaries to open a blank browser in Chrome.

https://chromedriver.chromium.org/

The chromedriver and geckodriver are placed in a folder name drivers in the RobotFramework_Demo project. I have renamed chromedriver to Chrome and geckodriver to Firefox.

Step 6 – Automate the selection of options for DropDown

We are now going to write test cases. The test case details will be as follows −

To work with the Radio Button, we need a locator. A locator is an identifier for the textbox like id, name, class, xpath, css selector, etc.

To know more about locators, refer to these Selenium Tutorials:

 Locators in Selenium – Locate by ID, ClassName,  Name, TagName,  LinkText, PartialLinkText

Dynamic XPath  in Selenium WebDriver

CSS Selector in Selenium WebDriver

The below page shows that we have multiple DropDown options.

Let us inspect the locator of DropDown.

Below is an example of selecting the options in DropDown.

*** Settings ***
Documentation    To validate the selection of DropDown
Library     SeleniumLibrary
Test Teardown    Close Browser

*** Test Cases ***
Select options in DropDown
    Open the Browser with URL
    Select the dropdown options APIs by value
    Select the dropdown options Microsoft Excel by index
    Select the dropdown options CSS by label

*** Keywords ***
Open the Browser with URL
    Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
    Go To    https://demo.automationtesting.in/Register.html
    Maximize Browser Window
    Set Selenium Implicit Wait    2

Select the dropdown options APIs by value
    Select From List By Value       id:Skills   APIs


Select the dropdown options Microsoft Excel by index
    Select From List By Index        id:Skills   43

Select the dropdown options CSS by label
    Select From List By Label       id:Skills   CSS


All the below-mentioned keywords are derived from SeleniumLibrary except the last one. The functionality of keywords mentioned above:

1. Create Webdriver − The keyword creates an instance of Selenium WebDriver.

2. Go To – This keyword navigates the current browser window to the provided URL – https://demo.automationtesting.in/Register.html.

3. Maximize Browser Window – This keyword maximizes the current browser window.

4. Set Selenium Implicit Wait – This keyword sets the implicit wait value used by Selenium.

5. Select From List By Value − This keyword is used to select APIs option from dropdown on the current page by value.

6. Select From List By Index – This keyword is used to select Microsoft Excel option from dropdown on the current page by index.

7. Select From List By Label – This keyword is used to select CSS option from the dropdown on the current page by label.

These keywords are present in SeleniumLibrary. To know more about these keywords, please refer to this document – https://robotframework.org/SeleniumLibrary/SeleniumLibrary.htm.

To run this script, go to the command line and go to directory tests.

Step 7 – Execute the tests

We need the below command to run the Robot Framework script.

robot DropDown_Demo.robot

The output of the above program is

Step 8 – View Report and Log

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s