Selenium WebDriver

View as Markdown

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
1{
2 "runtime": "my-browser",
3 "steps": [
4 {
5 "call": "driver.get",
6 "args": ["https://example.com"]
7 }
8 ]
9}

The call field maps directly to the method name. args is a JSON array of the method’s arguments.

get(url)

Navigate to a URL.

1await runtime.driver.get('https://example.com');
ParameterTypeRequiredDescription
urlstringYesURL to navigate to

getCurrentUrl()

Get the current page URL.

1const url = await runtime.driver.getCurrentUrl();

Returns string


getTitle()

Get the current page title.

1const title = await runtime.driver.getTitle();

Returns string


getPageSource()

Get the full HTML source of the current page.

1const html = await runtime.driver.getPageSource();

Returns string


Access the navigation interface for back/forward/refresh.

1await runtime.driver.navigate().to('https://example.com');
2await runtime.driver.navigate().back();
3await runtime.driver.navigate().forward();
4await runtime.driver.navigate().refresh();

Returns Navigation — object with to(), back(), forward(), refresh() methods.


Queries

findElement(locator)

Find a single element on the page.

1const el = await runtime.driver.findElement({ css: '#login' });
ParameterTypeRequiredDescription
locatorLocatorYesElement locator ({ css }, { xpath }, { id }, etc.)

Returns RemoteWebElement


findElements(locator)

Find all matching elements on the page.

1const items = await runtime.driver.findElements({ css: '.item' });
ParameterTypeRequiredDescription
locatorLocatorYesElement locator

Returns RemoteWebElement[]


Evaluation

executeScript(script, …args)

Execute synchronous JavaScript in the browser.

1const result = await runtime.driver.executeScript('return document.title');
ParameterTypeRequiredDescription
scriptstringYesJavaScript to execute
...argsany[]NoArguments passed to the script

Returns any


executeAsyncScript(script, …args)

Execute asynchronous JavaScript. The last argument to the script is a callback.

1const result = await runtime.driver.executeAsyncScript(
2 'const cb = arguments[arguments.length - 1]; setTimeout(() => cb("done"), 1000);'
3);
ParameterTypeRequiredDescription
scriptstringYesJavaScript to execute
...argsany[]NoArguments passed to the script

Returns any


Screenshots

takeScreenshot()

Take a screenshot of the current page.

1const base64 = await runtime.driver.takeScreenshot();

Returns string — base64-encoded PNG.


Cookies

manage().getCookies()

Get all cookies.

1const cookies = await runtime.driver.manage().getCookies();

manage().getCookie(name)

Get a specific cookie by name.

1const cookie = await runtime.driver.manage().getCookie('session');

manage().addCookie(cookie)

Add a cookie.

1await runtime.driver.manage().addCookie({ name: 'token', value: 'abc123' });

manage().deleteCookie(name)

Delete a specific cookie.

1await runtime.driver.manage().deleteCookie('session');

manage().deleteAllCookies()

Delete all cookies.

1await runtime.driver.manage().deleteAllCookies();

Window Management

getWindowHandle()

Get the current window handle.

1const handle = await runtime.driver.getWindowHandle();

Returns string


getAllWindowHandles()

Get all window handles.

1const handles = await runtime.driver.getAllWindowHandles();

Returns string[]


manage().window().getRect()

Get the window’s position and size.

1const rect = await runtime.driver.manage().window().getRect();

manage().window().setRect(rect)

Set the window’s position and size.

1await runtime.driver.manage().window().setRect({ width: 1280, height: 720 });

manage().window().maximize()

Maximize the window.

1await runtime.driver.manage().window().maximize();

manage().window().minimize()

Minimize the window.

1await runtime.driver.manage().window().minimize();

manage().window().fullscreen()

Enter fullscreen mode.

1await runtime.driver.manage().window().fullscreen();

Frame & Window Switching

switchTo().window(handle)

Switch to a different window or tab.

1await runtime.driver.switchTo().window(handle);

switchTo().frame(indexOrElement)

Switch into a frame by index or element.

1await runtime.driver.switchTo().frame(0);

switchTo().parentFrame()

Switch to the parent frame.

1await runtime.driver.switchTo().parentFrame();

switchTo().defaultContent()

Switch back to the main document.

1await runtime.driver.switchTo().defaultContent();

switchTo().activeElement()

Get the currently focused element.

1const el = await runtime.driver.switchTo().activeElement();

Returns RemoteWebElement


switchTo().alert()

Switch to an alert dialog. Returns an alert object with accept(), dismiss(), getText(), sendKeys().

1const alert = await runtime.driver.switchTo().alert();
2const text = await alert.getText();
3await alert.accept();

Lifecycle

close()

Close the current window.

1await runtime.driver.close();

quit()

Quit the driver and close all windows.

1await runtime.driver.quit();