Complete Guide with Examples
Robot Framework Browser Library is a modern browser automation library built on top of Playwright. It provides powerful keywords for automating Chromium, Chrome, Edge, and Firefox browsers. In this guide, we will explore the most useful Robot Framework Browser Library keywords with practical examples.
We will cover:
- Importing the Browser Library
- Launching Chromium, Chrome, Edge, and Firefox
- Opening web pages
- Getting the page URL and title
- Locating elements
- Filling text fields
- Clicking elements
- Getting element properties and attributes
- HTTP requests
- Hovering and highlighting elements
- Browser navigation
- Scrolling
- Drag and drop
- Dropdowns
- Checkboxes
- JavaScript alerts
- iFrames
- Keyboard actions
- Screenshots
Create a Robot Framework Test File
Create a file with the .robot extension.
For example:
browser_keywords.robot
A Robot Framework test file generally contains sections such as:
*** Settings ****** Variables ****** Test Cases ****** Keywords ***
For Browser Library automation, the library is imported in the *** Settings *** section.
1. Importing the Robot Framework Browser Library
The Browser Library can be imported using the Library setting.
*** Settings ***Library Browser
Once the Browser Library is imported, its keywords become available in the test file.
2. Launching a New Browser
The New Browser keyword is used to launch a browser.
Launch Chromium in Headed Mode
New Browser browser=chromium headless=false
The headless argument controls whether the browser UI is visible.
By default:
headless=true
Therefore, the following launches the browser in headless mode:
New Browser browser=chromium
To see the browser window during test execution:
New Browser browser=chromium headless=false
Launch Microsoft Edge
Microsoft Edge also uses the Chromium browser engine.
You can launch Edge by using the channel argument:
New Browser... browser=chromium... channel=msedge... headless=false
The channel argument specifies the installed browser channel.
Launch Firefox
To launch Firefox:
New Browser browser=firefox headless=false
The Browser Library supports different browser engines, including:
- Chromium
- Firefox
- WebKit
3. Opening a Web Page
The New Page keyword can be used to open a web page.
New Page https://example.com
You can also store the URL in a variable:
*** Variables ***${URL} https://example.com*** Test Cases ***Open Website New Page ${URL}
When New Page is used without explicitly creating a browser and context, the Browser Library can use its default browser and context settings.
New Page ${URL}
Another Way to Open a Browser and URL
You can also use:
Open Browser https://example.com browser=chromium headless=false
This opens the specified URL in the selected browser.
4. Get the Current Page URL
The Get Url keyword returns the current page URL.
${CURRENT_URL} Get UrlLog To Console ${CURRENT_URL}
Example output:
https://example.com/register
This is useful when validating navigation.
${CURRENT_URL} Get UrlShould Be Equal ${CURRENT_URL} https://example.com/register
5. Get the Page Title
The Get Title keyword returns the title of the current page.
${PAGE_TITLE} Get TitleLog To Console ${PAGE_TITLE}
You can also validate the title:
${PAGE_TITLE} Get TitleShould Be Equal ${PAGE_TITLE} Example Domain
6. Locating Elements in Browser Library
Locators are one of the most important parts of browser automation.
The Browser Library supports several locator strategies, including:
- Text
- CSS selectors
- IDs
- XPath
- Playwright-style locators
- Roles
- Labels
- Placeholders
- Test IDs
- Titles
- Alt text
Locate an Element by Text
You can click an element using its visible text.
Click text=Register
You can also write:
Click "Register"
For example:
Click text="Register"
This is useful when the visible text uniquely identifies the element.
Locate Using CSS Selectors
Consider the following HTML:
<li> <a class="ico-register">Register</a></li>
You can locate the anchor element using:
Click css=li > a.ico-register
Here:
liis the parent elementais the child element.ico-registerrepresents the CSS class
The same locator can also be written as:
Click li > .ico-register
CSS > and >> Selectors
The > and >> operators can be used to navigate through elements.
For example:
Type Text css=div > input#FirstName txt
Here:
div > input#FirstName
means that the input element is a direct child of the div.
The # symbol represents an ID selector.
Another way is:
Type Text css=div >> id=FirstName txt
The important difference is that the locator after >> can be a Browser Library or Playwright-style locator.
For example:
css=div > input#FirstName
uses the HTML element input.
Whereas:
css=div >> id=FirstName
uses the id locator directly.
Locate Elements Using XPath
XPath can be used in the traditional way:
Type Text xpath=//*[@id="LastName"] rotebit
You can also omit the xpath= prefix:
Type Text //*[@id="LastName"] rotebit
For example:
Click //button[text()=" Login "]
XPath remains useful when the element has complex relationships with other elements.
7. Playwright-Style Locators Using Get Element By
The Browser Library provides the Get Element By keyword to support Playwright-style locator methods.
These include:
page.getByAltText()page.getByLabel()page.getByPlaceholder()page.getByTestId()page.getByText()page.getByTitle()
For example:
${element} Get Element By text=RegisterClick ${element}
You can also use:
${username} Get Element By placeholder=UsernameFill Text ${username} Admin
The Browser Library also supports role-based locators using:
Get Element By Role
For example:
${button} Get Element By Role button name=LoginClick ${button}
Role-based locators are useful because they identify elements according to their accessible role.
8. Filling Input Fields
The Fill Text keyword fills an input field.
Fill Text input[name="username"] Admin
You can also use XPath:
Fill Text xpath=//input[@name="username"] Admin
Another example:
Fill Text input[name="password"] admin123
A complete example:
Fill Text input[name="username"] AdminFill Text input[name="password"] admin123Click //button[text()=" Login "]
9. Typing Text Character by Character
The Type Text keyword can be used when you want text to be typed character by character.
Type Text id=small-searchterms samsung delay=1000ms
The delay argument introduces a delay between keystrokes.
This can be useful for testing:
- Search suggestions
- Autocomplete fields
- Real-time validation
- Keyboard-driven UI behavior
For example:
Type Text id=search samsung delay=100ms
10. Double Click and Right Click
The Click With Options keyword allows you to customize the click action.
Double Click
Click With Options... //h2[contains(text(), 'Personal')]... clickCount=2
The clickCount=2 option performs a double click.
Right Click
Click With Options... id=LastName... button=right
The button=right option performs a right-click action.
11. Get an Element
The Get Element keyword retrieves an element.
${element} Get Element li > .ico-registerLog ${element}
The element can then be stored in a variable and reused.
12. Get Element Properties
The Get Property keyword retrieves a property from an element.
For example, to get the href value of an anchor element:
${element} Get Element li > .ico-register${link} Get Property ${element} hrefLog ${link}
This can return a URL such as:
https://example.com/register
13. Get Attribute Names
The Get Attribute Names keyword returns the names of the attributes associated with an element.
${attr_name} Get Attribute Names... //*[@id="app"]/div/div/div[1]Log ${attr_name}
This is useful when you need to inspect the attributes of an element.
14. Get an Attribute Value
Use the Get Attribute keyword to retrieve the value of a specific attribute.
${attr} Get Attribute... //*[@id="app"]/div... classLog ${attr}
For example, the result might be:
main-container
15. Get Text from an Element
The Get Text keyword retrieves visible text from an element.
${text} Get Text xpath=//div[@class='main-header']Log ${text}
You can use the value for validation:
${text} Get Text xpath=//div[@class='main-header']Should Be Equal ${text} Welcome
16. Making HTTP Requests with the Http Keyword
The Browser Library also provides the Http keyword.
For example, suppose you retrieve a link from an anchor element:
${element} Get Element li > .ico-register${link} Get Property ${element} href
You can then use the URL with the Http keyword:
&{res} Http ${link}
The response can be stored in a dictionary variable.
Log ${res}
This can be useful for verifying whether a link is accessible.
17. Hovering Over Elements
The Hover keyword moves the mouse pointer over an element.
Hover //ul[1]/li[1]/a
This is useful for testing:
- Menus
- Tooltips
- Hover-based dropdowns
- Navigation menus
Example:
Hover //nav//a[text()="Products"]
18. Highlighting Elements
The Highlight Elements keyword can visually highlight an element during test execution.
Highlight Elements... id=alertButton... duration=2000ms... width=5px... style=solid... color=\#FF0000
The keyword allows you to configure:
- The selector
- Highlight duration
- Border width
- Border style
- Highlight color
For example:
Highlight Elements... id=alertButton... duration=2000ms... width=5px... style=solid... color=\#FF0000
This can be helpful when debugging locator problems or demonstrating test execution.
19. Browser Navigation
The Browser Library provides keywords for browser navigation.
Go Back
Go Back
This navigates to the previous page.
Go Forward
Go Forward
This navigates to the next page in the browser history.
Example:
New Page https://example.comClick text=RegisterGo BackGo Forward
20. Scrolling the Page
The Browser Library provides several scrolling keywords.
Scroll by a Specific Amount
Scroll By ${None} 300 0 smooth
The parameters represent the scrolling amount.
Scroll to the Bottom
Scroll To ${None} bottom left auto
This can be useful for pages with infinite scrolling or lazy-loaded content.
Scroll to an Element
Scroll To Element xpath=//div/p
This scrolls the page until the specified element becomes visible.
21. Drag and Drop
The Browser Library provides the Drag And Drop keyword.
First, wait for the source and destination elements to become visible:
Wait For Elements State... //div[@id='draggable']... visibleWait For Elements State... //div[1]/div/div[@id='droppable']... visible
Scroll to the draggable element:
Scroll To Element //div[@id='draggable']
Perform drag and drop:
Drag And Drop... //div[@id='draggable']... //div[1]/div/div[@id='droppable']
A complete example:
Wait For Elements State... //div[@id='draggable']... visibleWait For Elements State... //div[1]/div/div[@id='droppable']... visibleScroll To Element //div[@id='draggable']Drag And Drop... //div[@id='draggable']... //div[1]/div/div[@id='droppable']
22. Drag and Drop Using Coordinates
Sometimes drag and drop needs to be performed using coordinates.
First, retrieve the bounding box of the source element:
&{drag} Get BoundingBox //div[@id='draggable']
Retrieve the bounding box of the destination:
&{drop} Get BoundingBox... //div[1]/div/div[@id='droppable']
The bounding box contains coordinate information.
You can retrieve the dictionary values:
@{list_drag} Get Dictionary Values ${drag}@{list_drop} Get Dictionary Values ${drop}
Then store the required coordinates:
${x_drag} Set Variable ${list_drag}[2]${y_drag} Set Variable ${list_drag}[3]${x_drop} Set Variable ${list_drop}[2]${y_drop} Set Variable ${list_drop}[3]
Finally, perform the drag and drop operation:
Drag And Drop By Coordinates... from_x=${x_drag}... from_y=${y_drag}... to_x=${x_drop}... to_y=${y_drop}
This approach can be useful when a standard drag-and-drop action does not work reliably.
23. Working with Dropdowns
The Browser Library provides keywords to interact with HTML select elements.
Get All Dropdown Options
${all_options} Get Select Options id=products-pagesizeLog ${all_options}
Get Selected Options
${selected_option} Get Selected Options... id=products-pagesizeLog ${selected_option}
Select an Option by Index
Select Options By... id=products-pagesize... index... 2
Deselect Options
Deselect Options id=products-pagesize
These keywords are especially useful when testing standard HTML <select> elements.
24. Working with Checkboxes
The Get Checkbox State keyword returns the current state of a checkbox.
${checkboxvalue} Get Checkbox State id=Newsletter
The result can be used with an IF condition.
For example:
IF ${checkboxvalue} Log Already Checked Uncheck Checkbox id=Newsletter Log Now UncheckedEND
Finally, check the checkbox:
Check Checkbox id=Newsletter
A complete example:
${checkboxvalue} Get Checkbox State id=NewsletterIF ${checkboxvalue} Log Already Checked Uncheck Checkbox id=Newsletter Log Now UncheckedENDCheck Checkbox id=Newsletter
This is useful when the initial state of a checkbox is not guaranteed.
25. Handling JavaScript Alerts
JavaScript dialogs can be handled using the Wait For Alert keyword.
The important concept is that Wait For Alert is commonly used with Promise To.
The promise is defined before clicking the element that opens the alert.
Promise To Wait For Alert action=acceptClick id=alertButton
The action can be:
acceptdismiss
For example:
Promise To Wait For Alert action=acceptClick id=alertButton
This accepts the alert.
Handling a Prompt Dialog
For an alert that contains an input field, use the prompt_input argument:
Promise To... Wait For Alert... action=accept... prompt_input="hello"Click id=promtButton
Using Handle Future Dialogs
Another option is the Handle Future Dialogs keyword.
Handle Future Dialogs... action=accept... prompt_input="hello"Click id=promtButton
This approach does not require Promise To.
26. Handling iFrames
The Browser Library supports iframe navigation using the >>> selector.
For example:
${frame1_text} Get Text... id=frame1 >>> id=sampleHeadingLog ${frame1_text}
Here:
id=frame1 >>> id=sampleHeading
means:
- Locate the iframe with
id=frame1 - Enter the iframe
- Locate the element with
id=sampleHeading
Another example:
${frame2_text} Get Text... id=frame2 >>> id=sampleHeading
You can also scroll to the iframe before interacting with it:
Scroll To Element id=frame1
27. Pressing Keyboard Keys
The Press Keys keyword is used for keyboard interactions.
For example:
Press Keys... //input[@name='username']... a... d... m... i... n
This types characters into the field.
Select All and Copy
Press Keys... //input[@name='username']... Control+A... Control+C
Paste Text
Press Keys... //input[@name='password']... Control+V... 1... 2... 3
Press Tab
Press Keys... //label[text()='Username']/parent::div/following-sibling::div/input... s... i... m... Tab
Clear Text Using Backspace
Press Keys... //label[text()='Username']/parent::div/following-sibling::div/input... Control+A... Backspace
Using Arrow Keys
Keyboard navigation can also be tested:
Press Keys... //*[contains(text(),'Employee')]/parent::div/following-sibling::div//input... ArrowDown... Enter
This is useful for:
- Autocomplete controls
- Dropdown menus
- Keyboard navigation
- Accessibility testing
28. Taking Screenshots
The Take Screenshot keyword can capture screenshots during test execution.
Take a Screenshot
Take Screenshot screenshot-{index}
The {index} placeholder can be used to create unique screenshot names.
For example:
Take Screenshot screenshot-{index}
Take a Full-Page Screenshot
Take Screenshot... fullPage=True... fileType=jpeg... quality=50
This captures the entire page.
You can configure:
- Full-page capture
- File type
- Image quality
Embed Screenshot in the Robot Framework Log
You can embed a screenshot directly into the Robot Framework log:
Take Screenshot EMBED
This is particularly useful when reviewing:
log.html
The screenshot becomes available directly inside the test execution report.
29. Complete Example Robot Framework Test File
The following example shows a basic Browser Library test structure.
*** Settings ***Library Browser*** Variables ***${URL} https://example.com*** Test Cases ***Browser Library Example New Browser browser=chromium headless=false New Page ${URL} ${CURRENT_URL} Get Url Log To Console ${CURRENT_URL} ${PAGE_TITLE} Get Title Log To Console ${PAGE_TITLE} Take Screenshot screenshot-{index}
A more complete test could look like this:
*** Settings ***Library Browser*** Variables ***${URL} https://example.com*** Test Cases ***Browser Automation Example New Browser browser=chromium headless=false New Page ${URL} ${CURRENT_URL} Get Url Log To Console ${CURRENT_URL} ${PAGE_TITLE} Get Title Log To Console ${PAGE_TITLE} ${text} Get Text xpath=//div[@class='main-header'] Log ${text} Scroll To ${None} bottom left auto Take Screenshot fullPage=True fileType=jpeg quality=50
Conclusion
The Robot Framework Browser Library provides a powerful collection of keywords for modern web automation.
Because it is built on Playwright, it supports modern browser automation capabilities while keeping the test syntax readable and keyword-driven.
The most commonly used Browser Library keywords include:
New BrowserNew PageGet UrlGet TitleClickFill TextType TextGet ElementGet TextGet AttributeHoverScroll To ElementDrag And DropSelect Options ByCheck CheckboxWait For AlertPress KeysTake Screenshot
Once you understand these keywords, you can build more advanced Robot Framework automation frameworks using the Page Object Model, reusable custom keywords, API integration, test data management, and CI/CD pipelines.
The Browser Library is therefore a strong choice for teams looking for modern browser automation with the simplicity and readability of Robot Framework.
Related Links
Browser Library Keywords Official Documentation
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.
