Cross_Column

Tuesday, 2 June 2026

Selenium Automation with Robot Framework



Selenium Automation with Robot Framework | Complete Beginner Tutorial

Selenium Automation with Robot Framework

Welcome to Phase 3 of Robot Framework Tutorial Series. In this tutorial, we will learn Selenium automation using Robot Framework with practical examples.

  • SeleniumLibrary
  • Web UI Automation Basics
  • Locators
  • Waits & Synchronization
  • Screenshots & Reporting

10. SeleniumLibrary in Robot Framework

SeleniumLibrary is the most popular library used for web automation in Robot Framework. It allows us to automate browser actions like:

  • Open browser
  • Click buttons
  • Enter text
  • Validate elements
  • Handle dropdowns

Install SeleniumLibrary

Run the following command in terminal:

pip install robotframework-seleniumlibrary

Install Selenium WebDriver

You also need browser drivers. For Chrome browser, install ChromeDriver.

Download ChromeDriver:

https://chromedriver.chromium.org/downloads


Import SeleniumLibrary

*** Settings ***
Library    SeleniumLibrary

Open Browser Example

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Open Google
    Open Browser    https://google.com    chrome
    Sleep    3s
    Close Browser

Explanation

Keyword Purpose
Open Browser Launch browser
Sleep Wait for few seconds
Close Browser Close browser window

11. Web UI Automation Basics

Web UI automation means automating browser activities like login, searching, clicking buttons, validating data etc.


Input Text Example

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Search Example
    Open Browser    https://google.com    chrome
    Input Text    name=q    Robot Framework
    Sleep    2s
    Close Browser

Click Element Example

Click Element    xpath=//button[@type='submit']

Handle Dropdown Example

Select From List By Label    id=country    India

Handle Radio Button Example

Select Radio Button    gender    Male

Handle Checkbox Example

Select Checkbox    id=terms

Handle Alerts Example

Handle Alert    accept

Handle Multiple Windows

Switch Window    NEW

Common SeleniumLibrary Keywords

Keyword Description
Click Element Click web element
Input Text Enter text in textbox
Get Text Read element text
Element Should Be Visible Validate element visibility
Page Should Contain Validate page content

12. Locators in Robot Framework

Locators are used to identify web elements on the webpage. Without locators, automation scripts cannot interact with web elements.


Types of Locators

Locator Example
id id=username
name name=email
class class=login-btn
xpath xpath=//input[@id='email']
css css=input[type='text']

ID Locator Example

Input Text    id=username    admin

Name Locator Example

Input Text    name=password    admin123

XPath Locator Example

Click Element    xpath=//button[text()='Login']

CSS Selector Example

Click Element    css=.submit-btn

Best Practices for Locators

  • Prefer ID locator whenever possible
  • Avoid long XPath
  • Use stable attributes
  • Create reusable locator variables

13. Waits & Synchronization in Robot Framework

Synchronization is one of the most important concepts in automation testing. Sometimes elements take time to load, so automation scripts need proper waits.


Problem Without Wait

If the script executes faster than webpage loading, tests may fail.


Sleep Keyword Example

Sleep    5s

Sleep pauses execution for fixed time. However, excessive use of Sleep is not recommended.


Wait Until Element Is Visible

Wait Until Element Is Visible    id=username    10s

Wait Until Page Contains

Wait Until Page Contains    Welcome    15s

Wait Until Element Is Enabled

Wait Until Element Is Enabled    id=submit

Why Explicit Waits are Better?

  • Improves test stability
  • Reduces unnecessary delays
  • Handles dynamic webpages
  • Reduces flaky tests

Best Practice

Always prefer explicit waits over Sleep whenever possible.


14. Screenshots & Reporting in Robot Framework

Robot Framework automatically generates detailed execution reports. It also supports screenshot capturing during failures.


Capture Screenshot Example

Capture Page Screenshot

Capture Screenshot on Failure

SeleniumLibrary automatically captures screenshots on failure if configured properly.


Generated Reports

After execution, Robot Framework generates:

  • log.html
  • report.html
  • output.xml

Purpose of Report Files

File Description
log.html Detailed execution logs
report.html Execution summary report
output.xml Raw execution data

Open Report Example

After test execution, simply open:

report.html

inside browser to see execution results.


Real-Time Reporting Benefits

  • Easy debugging
  • Execution tracking
  • Failure screenshots
  • Detailed logs

Complete Selenium Automation Example

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Google Search Test

    Open Browser    https://google.com    chrome

    Wait Until Element Is Visible    name=q    10s

    Input Text    name=q    Robot Framework Tutorial

    Capture Page Screenshot

    Sleep    2s

    Close Browser

Best Practices for Beginners

  • Use reusable keywords
  • Avoid unnecessary Sleep
  • Use proper waits
  • Use stable locators
  • Capture screenshots during failures

Conclusion

In this tutorial, we learned:

  • SeleniumLibrary installation
  • Web UI automation basics
  • Locators
  • Waits & synchronization
  • Screenshots & reporting

These concepts are the foundation of Selenium automation using Robot Framework.

In upcoming tutorials, we will learn:

  • Framework Design
  • Data-Driven Testing
  • Resource Files
  • Custom Keywords

Frequently Asked Questions (FAQ)

What is SeleniumLibrary in Robot Framework?

SeleniumLibrary is used for browser automation in Robot Framework.

What are locators?

Locators identify web elements on webpage for automation.

Why are waits important?

Waits help synchronize automation scripts with webpage loading.

Which locator is best?

ID locator is generally the fastest and most reliable locator.

No comments:

Post a Comment

Few More

CI/CD & Industry Usage

CI/CD in Robot Framework | Git, GitHub, Jenkins, Bitbucket & GitHub Actions CI/CD & I...