Skip to content

Browser automation with Selenium: starts Chrome (default) or Firefox and returns a Browser to drive it. `Sel.start()` opens a new browser; every call gives an independent browser with its own session. Pages, elements, waits and failure handling are documented on Browser and Locator, including the selector syntax. For a Playwright based alternative that drives Chromium only, see `Play`. Window size, headless mode and the default timeout come from the project's settings. Chrome is the Chrome for Testing that the agent downloads. When the agent runs with `agent.selenium.docker=true`, the browser runs in a `selenium/standalone-chrome` or `selenium/standalone-firefox` Docker container instead (headless does not apply there); files the browser downloads are copied to the project's `.downloads` folder. The run's replay policy controls recording. Downloads in a local Chrome also go to `.downloads`. Close what you open: `browser.close()` for one browser, `Sel.close()` for all of them. After `Sel.close()` the library no longer starts browsers.

  • Kind Library, a global in every script
  • Category Browser
  • Functions 3

Objects

Functions

  • start Browser Opens a new browser and returns it.
  • close self Closes every browser this library has opened (the same as calling `close()` on each of them) and stops the Docker container in Docker mode, copying its downloads to `.downloads`.
  • sleep self Pauses the script for a number of whole seconds; fractions are cut off, so `Sel.sleep(0.5)` does not sleep.
Sel.start()→BrowserSel.start(firefox: boolean)→Browser

Opens a new browser and returns it. Chrome is the default; pass `true` for Firefox, which Selenium starts itself (the agent does not download it as it does for Chrome; in Docker mode the image provides it). Fails with an error when the browser cannot be started. After `Sel.close()` it does not start a browser but returns the Sel library itself, so only use the result for a browser you know is open.

Parameters

firefox boolean optional
`true` starts Firefox instead of Chrome. Default `false`

Returns

Browser An open browser window with its tabs, driven by Selenium (`Sel.start()`) or Playwright (`Play.start()`).

Example 1

local browser = Sel.start()
browser.navigate("https://example.com")
print(browser.locator("xpath=//h1").text())
browser.close()

Example 2

Start Firefox instead of Chrome

local browser = Sel.start(true) -- Firefox
browser.navigate("https://example.com")
print(browser.url())
browser.close()
Sel.close()→self

Closes every browser this library has opened (the same as calling `close()` on each of them) and stops the Docker container in Docker mode, copying its downloads to `.downloads`. From then on `Sel.start()` raises an error and `Sel.sleep()` returns at once. Safe to call more than once.

Returns

self chainable The library itself, so calls can be chained.
Sel.sleep(seconds: number)→self

Pauses the script for a number of whole seconds; fractions are cut off, so `Sel.sleep(0.5)` does not sleep. It sleeps in steps of one second and returns early once the library has been closed, for example when the run is stopped. Prefer waiting for a condition (`locator.wait`, `locator.exists`) to a fixed sleep.

Parameters

seconds number
Number of seconds to sleep

Returns

self chainable The library itself, so calls can be chained.