*** title: Selenium WebDriver description: Complete WebDriver method reference for the Selenium driver. ------------------------------------------------------------------------- All `WebDriver` methods available when using the **Selenium** driver. Access via `runtime.driver` (or `runtime.webDriver`) after launching a Selenium runtime. Every method below is a remote call. The SDK translates it into a structured step sent to a single endpoint: ``` POST /v1/workspaces/{workspaceId}/execute ``` ```json { "runtime": "my-browser", "steps": [ { "call": "driver.get", "args": ["https://example.com"] } ] } ``` The `call` field maps directly to the method name. `args` is a JSON array of the method's arguments. ## Navigation ### get(url) Navigate to a URL. ```ts await runtime.driver.get('https://example.com'); ``` | Parameter | Type | Required | Description | | --------- | -------- | -------- | ------------------ | | `url` | `string` | Yes | URL to navigate to | *** ### getCurrentUrl() Get the current page URL. ```ts const url = await runtime.driver.getCurrentUrl(); ``` **Returns** `string` *** ### getTitle() Get the current page title. ```ts const title = await runtime.driver.getTitle(); ``` **Returns** `string` *** ### getPageSource() Get the full HTML source of the current page. ```ts const html = await runtime.driver.getPageSource(); ``` **Returns** `string` *** ### navigate() Access the navigation interface for back/forward/refresh. ```ts await runtime.driver.navigate().to('https://example.com'); await runtime.driver.navigate().back(); await runtime.driver.navigate().forward(); await runtime.driver.navigate().refresh(); ``` **Returns** `Navigation` — object with `to()`, `back()`, `forward()`, `refresh()` methods. *** ## Queries ### findElement(locator) Find a single element on the page. ```ts const el = await runtime.driver.findElement({ css: '#login' }); ``` | Parameter | Type | Required | Description | | --------- | --------- | -------- | -------------------------------------------------------- | | `locator` | `Locator` | Yes | Element locator (`{ css }`, `{ xpath }`, `{ id }`, etc.) | **Returns** `RemoteWebElement` *** ### findElements(locator) Find all matching elements on the page. ```ts const items = await runtime.driver.findElements({ css: '.item' }); ``` | Parameter | Type | Required | Description | | --------- | --------- | -------- | --------------- | | `locator` | `Locator` | Yes | Element locator | **Returns** `RemoteWebElement[]` *** ## Evaluation ### executeScript(script, ...args) Execute synchronous JavaScript in the browser. ```ts const result = await runtime.driver.executeScript('return document.title'); ``` | Parameter | Type | Required | Description | | --------- | -------- | -------- | ------------------------------ | | `script` | `string` | Yes | JavaScript to execute | | `...args` | `any[]` | No | Arguments passed to the script | **Returns** `any` *** ### executeAsyncScript(script, ...args) Execute asynchronous JavaScript. The last argument to the script is a callback. ```ts const result = await runtime.driver.executeAsyncScript( 'const cb = arguments[arguments.length - 1]; setTimeout(() => cb("done"), 1000);' ); ``` | Parameter | Type | Required | Description | | --------- | -------- | -------- | ------------------------------ | | `script` | `string` | Yes | JavaScript to execute | | `...args` | `any[]` | No | Arguments passed to the script | **Returns** `any` *** ## Screenshots ### takeScreenshot() Take a screenshot of the current page. ```ts const base64 = await runtime.driver.takeScreenshot(); ``` **Returns** `string` — base64-encoded PNG. *** ## Cookies ### manage().getCookies() Get all cookies. ```ts const cookies = await runtime.driver.manage().getCookies(); ``` *** ### manage().getCookie(name) Get a specific cookie by name. ```ts const cookie = await runtime.driver.manage().getCookie('session'); ``` *** ### manage().addCookie(cookie) Add a cookie. ```ts await runtime.driver.manage().addCookie({ name: 'token', value: 'abc123' }); ``` *** ### manage().deleteCookie(name) Delete a specific cookie. ```ts await runtime.driver.manage().deleteCookie('session'); ``` *** ### manage().deleteAllCookies() Delete all cookies. ```ts await runtime.driver.manage().deleteAllCookies(); ``` *** ## Window Management ### getWindowHandle() Get the current window handle. ```ts const handle = await runtime.driver.getWindowHandle(); ``` **Returns** `string` *** ### getAllWindowHandles() Get all window handles. ```ts const handles = await runtime.driver.getAllWindowHandles(); ``` **Returns** `string[]` *** ### manage().window().getRect() Get the window's position and size. ```ts const rect = await runtime.driver.manage().window().getRect(); ``` *** ### manage().window().setRect(rect) Set the window's position and size. ```ts await runtime.driver.manage().window().setRect({ width: 1280, height: 720 }); ``` *** ### manage().window().maximize() Maximize the window. ```ts await runtime.driver.manage().window().maximize(); ``` *** ### manage().window().minimize() Minimize the window. ```ts await runtime.driver.manage().window().minimize(); ``` *** ### manage().window().fullscreen() Enter fullscreen mode. ```ts await runtime.driver.manage().window().fullscreen(); ``` *** ## Frame & Window Switching ### switchTo().window(handle) Switch to a different window or tab. ```ts await runtime.driver.switchTo().window(handle); ``` *** ### switchTo().frame(indexOrElement) Switch into a frame by index or element. ```ts await runtime.driver.switchTo().frame(0); ``` *** ### switchTo().parentFrame() Switch to the parent frame. ```ts await runtime.driver.switchTo().parentFrame(); ``` *** ### switchTo().defaultContent() Switch back to the main document. ```ts await runtime.driver.switchTo().defaultContent(); ``` *** ### switchTo().activeElement() Get the currently focused element. ```ts const el = await runtime.driver.switchTo().activeElement(); ``` **Returns** `RemoteWebElement` *** ### switchTo().alert() Switch to an alert dialog. Returns an alert object with `accept()`, `dismiss()`, `getText()`, `sendKeys()`. ```ts const alert = await runtime.driver.switchTo().alert(); const text = await alert.getText(); await alert.accept(); ``` *** ## Lifecycle ### close() Close the current window. ```ts await runtime.driver.close(); ``` *** ### quit() Quit the driver and close all windows. ```ts await runtime.driver.quit(); ```