Robot Framework Python: Install, Extend and Build Custom Libraries
Robot Framework Python integration explained: virtual environments, custom keyword libraries, decorators, type hints, variable files and logging from Python.
Read article
Robot Framework Selenium testing means using SeleniumLibrary, a popular external library that connects Robot Framework keywords to Selenium WebDriver. With it, a test can open a browser, fill forms, click buttons and verify page content using readable steps that the whole team can review.
SeleniumLibrary wraps Selenium WebDriver in a large set of ready-made keywords. Instead of writing Python code for every interaction, you call keywords such as Open Browser, Input Text and Page Should Contain, while the library handles WebDriver sessions, element lookup and screenshots on failure.
Install the library into the same virtual environment as Robot Framework. The package name on PyPI is robotframework-seleniumlibrary, and pip also brings in the Selenium Python bindings it depends on.
python -m pip install robotframework robotframework-seleniumlibrary
You also need a browser such as Chrome, Firefox or Edge. Recent Selenium releases include Selenium Manager, which can locate or download a matching driver automatically, so manual driver setup is often unnecessary on a typical workstation.
Import the library in the Settings section, define the target URL as a variable and write a test that opens the page, interacts with it and checks the result. Keeping locators and URLs in variables makes the suite easier to adapt to other environments.
*** Settings ***
Library SeleniumLibrary
Suite Teardown Close All Browsers
*** Variables ***
${URL} https://example.com/login
${BROWSER} chrome
*** Test Cases ***
Log In With Valid User
Open Browser ${URL} ${BROWSER}
Input Text id:username demo
Input Password id:password ${PASSWORD}
Click Button Log in
Page Should Contain Welcome
Pass the password from the command line with --variable PASSWORD:secret instead of storing it in the file. Run the suite with robot as usual and review log.html to see each browser action in order.
SeleniumLibrary identifies elements with locators written as a strategy prefix followed by a value. Choosing stable locators is the single biggest factor in keeping browser suites reliable when the user interface changes.
| Strategy | Example | When to use |
|---|---|---|
| id | id:username | Unique, stable IDs are the most reliable choice |
| name | name:email | Form fields with consistent name attributes |
| css | css:button.primary | Flexible selection by class or structure |
| xpath | xpath://h1[text()="Sign in"] | Text-based or complex relationships |
| link | link:Forgot password? | Anchors identified by visible text |
Ask developers to add dedicated test attributes such as data-testid where possible, and target them with a CSS locator. These attributes rarely change during visual redesigns.
Modern pages load content asynchronously, which is the most common source of flaky tests. Avoid fixed Sleep calls and use waiting keywords that poll until a condition is met or a timeout expires.
Wait Until Element Is Visible for elements that appear after loadingWait Until Page Contains for text rendered by scriptsWait Until Element Is Enabled before clicking buttons that start disabledSet Selenium Timeout to adjust the default waiting time for a suiteLong tests full of locators become hard to maintain. Move page-specific actions into user keywords inside resource files, one per page or feature, so tests describe user goals and locators live in a single place.
*** Keywords ***
Log In As
[Arguments] ${user} ${password}
Input Text id:username ${user}
Input Password id:password ${password}
Click Button Log in
This pattern follows the same principles described in the Robot Framework keywords overview, where user keywords act as a readable layer above library keywords.
Continuous integration servers usually have no display, so browsers run in headless mode. SeleniumLibrary accepts browser names such as headlesschrome and headlessfirefox, which makes switching between local and CI runs a matter of changing one variable.
Browser library is another popular choice for web testing in the Robot Framework ecosystem. It is built on Playwright rather than Selenium and offers automatic waiting, browser contexts and network control, while requiring Node.js during installation.
| Aspect | SeleniumLibrary | Browser library |
|---|---|---|
| Engine | Selenium WebDriver | Playwright |
| Extra runtime | Browser and driver | Node.js and Playwright browsers |
| Waiting model | Explicit wait keywords | Built-in automatic waiting |
| Maturity | Long history and wide adoption | Newer, actively developed |
A failing browser test is easiest to diagnose from log.html, where the failing keyword, its arguments and an automatic screenshot appear together. Comparing the screenshot with the expected page state usually reveals whether the problem is timing, a changed locator or a real application bug.
No. SeleniumLibrary is an external library installed separately with pip. The core package includes standard libraries such as BuiltIn, Collections and OperatingSystem, but not browser automation.
Any browser supported by Selenium WebDriver can be used, including Chrome, Firefox, Edge and Safari, as long as the matching driver is available on the machine running the tests.
Call Capture Page Screenshot at any point in a test. The image is saved next to the log and embedded in log.html, which helps document important states.
Run headless, avoid fixed sleeps, reuse a logged-in session where it is safe and run suites in parallel with Pabot. Stable locators also reduce slow retries.
Yes. Browsers can be resized or started with device emulation options, and AppiumLibrary covers native mobile apps when full device automation is required.
For a search page that updates without a full reload, define what a completed search looks like before choosing a wait. The visible results area might exist before the response arrives, so wait for a specific result or an empty state message associated with the submitted search query. Use a locator that identifies that region uniquely. This makes a slow response and a genuine mismatch easier to distinguish in the test log.
Robot Framework Selenium suites combine SeleniumLibrary’s browser keywords with readable test data, stable locators and explicit waits. Start with one login flow, move page actions into resource files and run headless in CI. For the underlying syntax, the Robot Framework tutorial is a good companion.