BROWSER

Recording keywords

What gets recorded

Which Browser keyword each action becomes, how popups, dialogs, downloads and uploads are handled, recording assertions, and the selectors the recorder writes.

Playwright watches the page and reports each action — a click, a fill, a key press. The recorder turns each one into a Keyword Call to a Browser keyword, the same keyword you would have written by hand.

Actions

YouRecorded as
ClickClick with the selector
Double-click, right-click, click with Shift / Ctrl / Alt / MetaClick With Options with the button, the modifiers and clickCount
Type into a fieldFill Text with the text — one call per field, however you typed it
Press Enter, Tab, Escape, a shortcutPress Keys, modifiers joined with +
Tick or untick a checkboxCheck Checkbox / Uncheck Checkbox
Choose in a <select>Select Options By with value and the chosen options
Navigate by URL or bookmarkGo To with the URL
Close a tabClose Page — see Working in several tabs
Click    role=button[name="Save"s]Click With Options    role=row[name*="Order 4711"i]    right    Shift    clickCount=2Fill Text    role=textbox[name*="Email"i]    jane@example.comPress Keys    role=textbox[name*="Search"i]    EnterCheck Checkbox    role=checkbox[name*="Remember me"i]Select Options By    role=combobox[name*="Country"i]    value    deGo To    https://shop.example.com/cart

A navigation within five seconds of a click, fill or key press belongs to that action — the click on a link is the navigation — so it gets no Go To of its own. A recorded keyword never opens a browser or a page: it runs in whatever page its caller set up, which is what makes it reusable.

Popups, dialogs, downloads and uploads

Some actions need Browser keywords around them. Playwright reports these after the action; the recorder puts the calls where Browser needs them. Undo removes them together with the action.

A new tab or popup is followed by switching to it:

Click    role=link[name="Open in new tab"s]Switch Page    NEW

Working in several tabs

The recorder knows which tab every action happens in. When the next action is in another tab than the last one, it switches there first. Switch Page returns the id of the tab it leaves, so the keyword can come back to it; the recorder assigns that id to a variable once an action needs it:

Click    role=link[name="Open in new tab"s]${page}=    Switch Page    NEWFill Text    role=textbox[name*="Search"i]    shoesSwitch Page    ${page}Click    role=button[name="Save"s]

Closing the active tab becomes Close Page; Browser then returns to the tab before it. Closing another tab closes it by its id: Close Page with ${page}. A tab that was already open when the recording started, or that you opened by hand, has no id the keyword knows: an action there is recorded without a switch, and the toolbar says so.

An alert, confirm or prompt gets its handler before the click that opens it. Playwright does not report whether you accepted it, so the recorder accepts:

Handle Future Dialogs    action=acceptClick    role=button[name="Delete"s]

A download is wrapped in a promise:

${download}=    Promise To Wait For DownloadClick    role=link[name="Export as CSV"s]Wait For    ${download}

An upload through a file chooser is wrapped the same way. The page never learns which folder the file came from, so the path starts with a placeholder; the toolbar reminds you to fill it in:

${upload}=    Promise To Upload File    <define_path_to_file>/report.zipClick    role=button[name="Open Report"s]Wait For    ${upload}

Replace <define_path_to_file> with the folder — ${CURDIR}/testdata — or mark it in the toolbar and make it an argument. When no click opened the chooser, the recorder sets the file on the input directly:

Upload File By Selector    input[type="file"]    <define_path_to_file>/report.zip

Assertions

A keyword that only clicks proves nothing. Playwright's toolbar at the top centre of the page has four assertion tools: pick one, then click the element to check.

Assert visibility, then assert text — each a Keyword Call with a retrying assertion.

ToolRecorded as
Assert visibility (eye)Get Element States with *= and visible
Assert text (ab)Get Text with contains and the text — or == when you check the whole text
Assert value, on a fieldGet Property with value, == and the value
Assert value, on a checkboxGet Checkbox State with == and checked or unchecked
Assert snapshotGet Aria Snapshot with yaml, == and the element's accessibility tree
*** Keywords ***Check The Assertions Page    [Tags]    recorded    Get Element States    role=heading[name*="Assertions"i]    *=    visible    Get Text    h1    contains    Assertions

These are ordinary Browser getters, so they retry until the page catches up — see Assertions. The expected values are arguments like any other: make Assertions an argument and the keyword checks any page.

Selectors

Playwright picks each selector the way its own code generator does: a test id if the element has one, then role and accessible name, placeholder, label, alt text, text and title, and CSS as a last resort — the best of these that finds only this element. The recorder writes them in Browser's public selector syntax, with the same meaning:

ElementRecorded selector
A link or button found by its namerole=link[name="Keywords"s] — exact; name*="…"i — contains, any case
An element with a test id[data-testid="theme-toggle"]
A field found by its placeholder[placeholder*="Email"i]
Text without a roletext=/^\s*Plain\s+text\s*$/ — the whole text, exactly
One of several similar elements… >> nth=1, or div:has-text("Card one")
Inside an iframe#frame >>> role=button[name*="Pay"i]
Two or more frames deep>>> #inner >>> role=button[name*="Pay"i] — in whichever frame it is
A widget known only by its labellabel="Map"i — from aria-label, aria-labelledby or a <label>

Every selector finds exactly the element you clicked when it was recorded; the library's tests check this for each kind of selector Playwright generates. Whether it still finds it tomorrow depends on the page: a name with a counter in it, like role=link[name*="Get Text 5"i], breaks when the count changes. Shorten such a selector, or make the changing part an argument.

Values are written exactly

Whatever you typed is what the keyword types, even where it means something to Robot Framework. Spaces Robot would read as a cell separator or strip at a cell edge are escaped with a backslash, so no two plain spaces meet:

Fill Text    id=ref       \#42                      # not a commentFill Text    id=name      two \ spaces              # not a cell separatorFill Text    id=path      \${HOME}/reports          # not a variableFill Text    id=note      first line\nsecond line   # a line breakFill Text    id=code      \ padded \                # edge spaces keptFill Text    id=tail      two trailing \ \          # both trailing spaces keptFill Text    id=empty     ${EMPTY}                  # the field was cleared

Password fields get no special treatment: what you type is recorded as typed. Make it an argument without a default, so the keyword never holds a secret — see Good practice and limits.

Not recorded

  • Hovering. Playwright does not report it. Add Hover by hand where a menu needs it.
  • Anything while the toolbar picks a selector with Pick in the toolbar or Pick locator in Playwright's — see Picking a selector.
  • Actions a later Playwright version adds. Every action Playwright reports today has a Browser keyword. One without names itself in a notice; the keyword stays as it was.
  • Other browser contexts. Only the context that was active when the recording started is recorded.