Implementation:MarketSquare Robotframework browser Get Text Get Title Get Property
| Property | Value |
|---|---|
| Implementation Name | Get Text, Get Title, Get Property |
| Type | API Doc |
| Domains | Test_Automation, Assertion |
| Workflow | Browser_Test_Authoring |
| Repository | MarketSquare/robotframework-browser |
Overview
Concrete tools for retrieving page state values with optional inline assertions provided by robotframework-browser.
Description
These getter keywords retrieve values from the current page and optionally assert that the values match expectations. All three keywords are decorated with @with_assertion_polling from Browser/assertion_engine.py, which enables automatic retry logic when assertion parameters are provided.
- Get Text: Returns the text content of the element found by the selector. For
inputandtextareaelements, returns thevalueproperty. Uses strict mode to ensure the selector matches exactly one element. - Get Title: Returns the title of the current page (the content of the
<title>tag). Does not require a selector since it operates on the page itself. - Get Property: Returns a specific DOM property of the element found by the selector. The property name is passed as a string argument (e.g.,
innerText,href,checked). ReturnsNonewhen the property is not found and an assertion operator is set; raisesAttributeErrorif no assertion operator is set.
All three keywords share the same assertion interface: optional assertion_operator, assertion_expected, and message parameters. When these are omitted, the keywords act as pure getters.
The @assertion_formatter_used decorator enables custom formatters that can normalize values before comparison (e.g., stripping whitespace, converting case).
Usage
Use these keywords to verify page content in test cases. Use Get Text for visible text content and form field values. Use Get Title to verify page titles during navigation flows. Use Get Property to access any DOM property that is not directly exposed by other getter keywords.
Code Reference
Source Location
- Repository: robotframework-browser
- Files:
Browser/keywords/getters.pyLines 220-264 (get_text)Browser/keywords/getters.pyLines 184-218 (get_title)Browser/keywords/getters.pyLines 272-329 (get_property)Browser/assertion_engine.pyLines 43-76 (with_assertion_polling decorator)
Signature
# Get Text
@keyword(tags=("Getter", "Assertion", "PageContent"))
@with_assertion_polling
@assertion_formatter_used
def get_text(
self,
selector: str,
assertion_operator: AssertionOperator | None = None,
assertion_expected: Any | None = None,
message: str | None = None,
) -> str
# Get Title
@keyword(tags=("Getter", "Assertion", "PageContent"))
@with_assertion_polling
@assertion_formatter_used
def get_title(
self,
assertion_operator: AssertionOperator | None = None,
assertion_expected: Any | None = None,
message: str | None = None,
) -> str
# Get Property
@keyword(tags=("Getter", "Assertion", "PageContent"))
@with_assertion_polling
@assertion_formatter_used
def get_property(
self,
selector: str,
property: str,
assertion_operator: AssertionOperator | None = None,
assertion_expected: Any | None = None,
message: str | None = None,
) -> Any
Import
# These are Robot Framework keywords exposed by the Browser library.
# No direct Python import is needed for typical usage.
# Robot Framework usage (in *** Settings ***):
# Library Browser
I/O Contract
Get Text
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
str | (required) | Selector for the element whose text to retrieve. |
assertion_operator |
AssertionOperator or None | None | Assertion operator (==, !=, contains, starts, ends, matches, evaluates, >, <, >=, <=). |
assertion_expected |
Any or None | None | Expected value for the assertion. |
message |
str or None | None | Custom error message that overrides the default on assertion failure. |
| Returns | Description |
|---|---|
| str | The text content of the element, or the value property for input/textarea elements. |
Get Title
| Parameter | Type | Default | Description |
|---|---|---|---|
assertion_operator |
AssertionOperator or None | None | Assertion operator for inline verification. |
assertion_expected |
Any or None | None | Expected value for the assertion. |
message |
str or None | None | Custom error message on assertion failure. |
| Returns | Description |
|---|---|
| str | The title of the current page. |
Get Property
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
str | (required) | Selector for the element to inspect. |
property |
str | (required) | Name of the DOM property to retrieve (e.g., innerText, href, checked). |
assertion_operator |
AssertionOperator or None | None | Assertion operator for inline verification. |
assertion_expected |
Any or None | None | Expected value for the assertion. |
message |
str or None | None | Custom error message on assertion failure. |
| Returns | Description |
|---|---|
| Any | The value of the requested property. Type depends on the property (str, bool, int, etc.). Returns None if property not found and assertion_operator is set. |
Usage Examples
*** Settings ***
Library Browser
*** Test Cases ***
Get Text Without Assertion (Pure Getter)
New Page https://example.com
${text}= Get Text id=heading
Log The heading text is: ${text}
Get Text With Equality Assertion
New Page https://example.com
${text}= Get Text id=heading == Welcome
# Returns "Welcome" or fails if text does not match
Get Text With Contains Assertion
New Page https://example.com
Get Text id=description contains important
Get Text With Custom Error Message
New Page https://example.com
Get Text id=status == Active message=Expected status to be Active but was not
Get Title With Assertion
New Page https://example.com
Get Title == Example Domain
Get Title Without Assertion
New Page https://example.com
${title}= Get Title
Log Page title is: ${title}
Get Property To Check Element State
New Page https://example.com/form
Get Property id=submit-btn innerText == Submit
Get Property id=checkbox checked == ${True}
Get Property With Starts Assertion
New Page https://example.com
Get Property css=a.link href starts https://
Get Text From Input Field
New Page https://example.com/form
Fill Text id=username testuser
${value}= Get Text id=username == testuser
Assertion With Evaluates Operator
New Page https://example.com
Get Text id=count evaluates int(value) > 0
Assertion With Regex Match
New Page https://example.com
Get Text id=email matches ^[\\w.-]+@[\\w.-]+\\.\\w+$