SeleniumLibrary (2024)

Introduction

SeleniumLibrary is a web testing library for Robot Framework thatutilizes the Selenium tool internally. The project is hosted on GitHuband downloads can be found from PyPI.

SeleniumLibrary currently works with Selenium 4. It supports Python 3.8 through 3.11.In addition to the normal Python interpreter, it works alsowith PyPy.

SeleniumLibrary is based on the "old SeleniumLibrary" that was forked toSelenium2Library and then later renamed back to SeleniumLibrary.See the VERSIONS.rst for more information about different versions and theoverall project history.

SeleniumLibrary (1)SeleniumLibrary (2)SeleniumLibrary (3)SeleniumLibrary (4)

Keyword Documentation

See keyword documentation for available keywords and more informationabout the library in general.

Installation

The recommended installation method is using pip:

pip install --upgrade robotframework-seleniumlibrary

Running this command installs also the latest Selenium and Robot Frameworkversions, but you still need to install browser drivers separately.The --upgrade option can be omitted when installing the library for thefirst time.

It is possible to install directly from the GitHub repository. To installlatest source from the master branch, use this command:

pip install git+https://github.com/robotframework/SeleniumLibrary.git

Please note that installation will take some time, because pip willclone the SeleniumLibrary project to a temporary directory and thenperform the installation.

See Robot Framework installation instructions for detailed informationabout installing Python and Robot Framework itself. For more details aboutusing pip see its own documentation.

Browser drivers

After installing the library, you still need to install browser andoperating system specific browser drivers for all those browsers youwant to use in tests. These are the exact same drivers you need to use withSelenium also when not using SeleniumLibrary. More information aboutdrivers can be found from Selenium documentation.

The general approach to install a browser driver is downloading a rightdriver, such as chromedriver for Chrome, and placing it intoa directory that is in PATH. Drivers for different browserscan be found via Selenium documentation or by using your favoritesearch engine with a search term like selenium chrome browser driver.New browser driver versions are released to support features innew browsers, fix bug, or otherwise, and you need to keep an eye on themto know when to update drivers you use.

Alternatively, you can use a tool called WebdriverManager which canfind the latest version or when required, any version of appropriatewebdrivers for you and then download and link/copy it into rightlocation. Tool can run on all major operating systems and supportsdownloading of Chrome, Firefox, Opera & Edge webdrivers.

Here's an example:

pip install webdrivermanagerwebdrivermanager firefox chrome --linkpath /usr/local/bin

Usage

To use SeleniumLibrary in Robot Framework tests, the library needs tofirst be imported using the Library setting as any other library.The library accepts some import time arguments, which are documentedin the keyword documentation along with all the keywords providedby the library.

When using Robot Framework, it is generally recommended to write aseasy-to-understand tests as possible. The keywords provided bySeleniumLibrary is pretty low level, though, and often requireimplementation-specific arguments like element locators to be passedas arguments. It is thus typically a good idea to write tests usingRobot Framework's higher-level keywords that utilize SeleniumLibrarykeywords internally. This is illustrated by the following examplewhere SeleniumLibrary keywords like Input Text are primarilyused by higher-level keywords like Input Username.

*** Settings ***Documentation Simple example using SeleniumLibrary.Library SeleniumLibrary*** Variables ***${LOGIN URL} http://localhost:7272${BROWSER} Chrome*** Test Cases ***Valid Login Open Browser To Login Page Input Username demo Input Password mode Submit Credentials Welcome Page Should Be Open [Teardown] Close Browser*** Keywords ***Open Browser To Login Page Open Browser ${LOGIN URL} ${BROWSER} Title Should Be Login PageInput Username [Arguments] ${username} Input Text username_field ${username}Input Password [Arguments] ${password} Input Text password_field ${password}Submit Credentials Click Button login_buttonWelcome Page Should Be Open Title Should Be Welcome Page

The above example is a slightly modified version of an example in ademo project that illustrates using Robot Framework and SeleniumLibrary.See the demo for more examples that you can also execute on your ownmachine. For more information about Robot Framework test data syntax ingeneral see the Robot Framework User Guide.

Extending SeleniumLibrary

Before creating your own library which extends the SeleniumLibrary, please consider wouldthe extension be also useful also for general usage. If it could be useful also for generalusage, please create a new issue describing the enhancement request and even better if theissue is backed up by a pull request.

If the enhancement is not generally useful, example solution is domain specific, then theSeleniumLibrary offers public APIs which can be used to build its own plugins and libraries.Plugin API allows us to add new keywords, modify existing keywords and modify the internalfunctionality of the library. Also new libraries can be built on top of theSeleniumLibrary. Please see extending documentation for more details about theavailable methods and for examples how the library can be extended.

Community

If the provided documentation is not enough, there are various community channelsavailable:

SeleniumLibrary (2024)
Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5730

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.