Interface WebDriver
-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public interface WebDriver implements Closeable
WebDriver defines a concise interface to visit and manipulate webpages. @mcp
The webpage is rendered to a Document Object Model (DOM) in a real browser, and the interface provides methods to control the browser, select textContent and attributes of Elements, and interact with the webpage.
All actions and behaviors are optimized to mimic real people as closely as possible, such as scrolling, clicking, typing text, dragging and dropping, etc.
The term
documenthere refers to a Document Object Model (DOM) within a browser.The methods in this interface fall into three categories:
Control of the browser itself
Selection of textContent and attributes of Elements
Interact with the webpage
Key methods:
navigate: navigate to a URL.
currentUrl: get the current URL displayed in the address bar.
scrollDown: scroll down on a webpage to fully load the page. Most modern webpages support lazy loading using ajax tech, where the page content only starts to load when it is scrolled into view.
pageSource: retrieve the source code of the webpage.
For each document, there are several properties that represent the URL of the document:
driver.currentUrl(): Returns the URL displayed in the address bar, it can be either navigated or not.driver.url(),document.URL: Returns the URL of the document.driver.documentURI(),document.documentURI: Returns the URI of the document.driver.baseURI(),document.baseURI: Returns the base URI of the document.document.location: Represents the location (URL) of the current page and allows you to manipulate the URL.
In the Document Object Model (DOM), the relationship between
document.URL,document.documentURI,document.location, and the URL displayed in the browser's address bar is as follows:driver.currentUrl():driver.url(),document.URL:driver.documentURI(),document.documentURI:driver.baseURI(),document.baseURI:document.location:
In summary,
document.URLanddocument.documentURIare read-only properties that reflect the current URL of the document, whiledocument.locationis a read-write property that not only reflects the current URL but also allows you to navigate to a new one. The URL displayed in the address bar is a user-facing representation of the current document's URL, which is usually in sync withdocument.location.In addition to the above properties, The method
driver.referrer()returns the document's referrer. Thedocument.referrerproperty returns the URI of the page that linked to the current page. If the user navigated directly to the page (e.g., via a bookmark), the value is an empty string. Inside an<iframe>, the referrer is initially set to the same value as thehrefof the parent window'sWindow.location.The following example demonstrates how to use the WebDriver interface to visit a webpage and interact with it:
fun visit() { val url = "https://twitter.com/home" val args = "-refresh" val options = session.options(args) options.eventHandlers.browseEventHandlers.onDocumentSteady.addLast { page, driver -> interact(page, driver) } session.load(url, options) } // interact with the page private suspend fun interact(driver: WebDriver) { val selector = "input[placeholder*=搜索], input[placeholder*=Search]" driver.waitForSelector(selector) driver.fill(selector, "Facebook") driver.press("Space", selector) "Email".forEach { driver.press("$it", selector) } driver.press("Enter", selector) }
-
-
Method Summary
Modifier and Type Method Description abstract UnitaddInitScript(String script)Adds a script which would be evaluated whenever the page is navigated. abstract UnitaddBlockedURLs(List<String> urlPatterns)Blocks resource URLs from loading. Unitopen(String url)Opens the specified URL in the web driver. abstract Unitnavigate(String url)Navigates current page to the given URL. abstract Unitnavigate(NavigateEntry entry)Navigates current page to the given URL. UnitnavigateTo(String url)abstract Unitreload()Reloads the current page. abstract UnitgoBack()Navigates the browser to the previous page in the navigation history. abstract UnitgoForward()Navigates the browser to the next page in the navigation history. abstract StringcurrentUrl()Returns a string representing the current URL that the browser is looking at. abstract Stringurl()The URL read-only property of the Document interface returns the document location as a string. abstract StringdocumentURI()Returns the document location as a string. abstract StringbaseURI()Returns the document's baseURI. abstract Stringreferrer()The referrer property returns the URI of the page that linked to this page. abstract StringpageSource()Returns the source of the last loaded page. abstract Stringtitle()Returns the title of the current page. abstract <Error class: unknown class>nanoDOMTree()Retrieves a lightweight version of the DOM tree (NanoDOMTree). abstract ModelResponsechat(String prompt, String selector)Interact with an AI model using the context of the element selected by selector. abstract List<Map<String, String>>getCookies()Returns the cookies of the current page. abstract UnitdeleteCookies(String name, String url, String domain, String path)Deletes browser cookies with matching name and url or domain/path pair. abstract UnitclearBrowserCookies()Clears browser cookies. DurationwaitForSelector(String selector)Wait until the element identified by the selector becomes present in the DOM or timeout. LongwaitForSelector(String selector, Long timeoutMillis)Wait until the element identified by the selector becomes present in the DOM or timeout. DurationwaitForSelector(String selector, Duration timeout)Wait for the element identified by the selector to become present in the DOM, or until timeout. abstract DurationwaitForSelector(String selector, SuspendFunction0<Unit> action)Wait for the element identified by the selector to become present in the DOM, or until timeout. LongwaitForSelector(String selector, Long timeoutMillis, SuspendFunction0<Unit> action)Wait for the element identified by the selector to become present in the DOM, or until timeout. abstract DurationwaitForSelector(String selector, Duration timeout, SuspendFunction0<Unit> action)Wait for the element identified by the selector to become present in the DOM, or until timeout. abstract DurationwaitForNavigation(String oldUrl)Wait until the current url changes or timeout. LongwaitForNavigation(String oldUrl, Long timeoutMillis)Wait until the current url changes or timeout. abstract DurationwaitForNavigation(String oldUrl, Duration timeout)Wait until the current url changes or timeout. abstract WebDriverwaitForPage(String url, Duration timeout)Await navigation to the specified URL page or timeout if necessary. abstract WebDriverwaitForFunction(String pageFunction, Duration timeout)Returns when the pageFunction returns a truthy value. abstract DurationwaitUntil(SuspendFunction0<Boolean> predicate)Wait until the predicate returns true. LongwaitUntil(Long timeoutMillis, SuspendFunction0<Boolean> predicate)Wait until the predicate returns true. abstract DurationwaitUntil(Duration timeout, SuspendFunction0<Boolean> predicate)Wait until the predicate returns true. abstract Booleanexists(String selector)Returns whether the element exists. BooleanisHidden(String selector)Returns whether the element is hidden. abstract BooleanisVisible(String selector)Returns whether the element is visible. abstract BooleanisChecked(String selector)Returns whether the element is checked. abstract UnitbringToFront()Brings the browser window to the front. abstract Unithover(String selector)This method hovers over the element. abstract Unitfocus(String selector)This method fetches an element with selectorand focuses it.abstract Unittype(String text, String selector)This method emulates inserting text that doesn't come from a key press. abstract Unitpress(String key, String selector)Shortcut for keyboard down and keyboard up. abstract Unitfill(String selector, String text)This method emulates inserting text that doesn't come from a key press. abstract UnitkeyDown(String key)Presses and holds a keyboard key on the currently focused element. abstract UnitkeyUp(String key)Releases a previously pressed keyboard key on the currently focused element. abstract Unitclick(String selector, Integer count)Focus on an element with selector and click it. abstract Unitclick(String selector, String modifier)Focus on an element with selector and click it with modifier pressed. abstract Unitdblclick(String selector)Focus on an element with selector and double-click it. abstract Unitdblclick(String selector, String modifier)Focus on an element with selector and double-click it with modifier pressed. abstract Unitresize(Integer width, Integer height)Resizes the viewport to the specified width and height. abstract UnitdialogAccept(String promptText)Accepts the dialog. abstract UnitdialogDismiss()Dismisses the dialog. abstract UnitclickTextMatches(String selector, String pattern, Integer count)This method clicks an element with selector whose text content matches pattern, and then focuses it. abstract UnitclickMatches(String selector, String attrName, String pattern, Integer count)This method clicks an element with selector whose attribute name is attrName and value matches pattern, and then focuses it. abstract List<String>selectOption(String selector, List<String> values)Selects one or more options in a <select> element. StringselectOption(String selector, String value)Selects an option in a <select> element. abstract Unitcheck(String selector)This method check an element with selector. abstract Unituncheck(String selector)This method uncheck an element with selector. abstract DoublescrollTo(String selector)This method fetches an element with selector, scrolls it into view if needed. abstract DoublescrollDown(Integer count)The current page frame scrolls down for count times. abstract DoublescrollUp(Integer count)The current page frame scrolls up for count times. abstract DoublescrollBy(Double pixels, Boolean smooth)Scrolls the current page frame vertically by the given number of pixels. abstract DoublescrollToTop()The current page frame scrolls to the top. abstract DoublescrollToBottom()The current page frame scrolls to the bottom. abstract DoublescrollToMiddle(Double ratio)The current page frame scrolls to the middle. abstract DoublescrollToViewport(Double n, Boolean smooth)Scroll to the 2.5th viewport position. abstract UnitmouseWheel(Double deltaX, Double deltaY)Scrolls the mouse wheel by the provided deltas. abstract UnitmouseMove(Double x, Double y)Moves the mouse to the position specified by x and y. abstract UnitmouseDown(String button, Integer clickCount)Presses a mouse button at the current mouse position. abstract UnitmouseUp(String button, Integer clickCount)Releases a mouse button at the current mouse position. abstract UnitmoveMouseTo(String selector, Integer deltaX, Integer deltaY)The mouse moves to the element with selector. abstract UnitdragAndDrop(String selector, Integer deltaX, Integer deltaY)Performs a drag, dragenter, dragover, and drop in sequence. Unitdrag(String sourceSelector, String targetSelector)Drags the element identified by sourceSelector onto the element identified by targetSelector. abstract StringouterHTML()Returns the document's HTML markup. abstract StringouterHTML(String selector)Returns the node's HTML markup, the node is located by selector. abstract StringtextContent(String selector)Returns the text content of the document or a specific element. abstract Map<String, String>extract(Map<String, String> fields)Extracts multiple fields from the page using CSS selectors. abstract List<NodeRef>querySelectorAll(String selector)Use querySelectorAll to get all elements matched by selector, and then return their NodeRefs. abstract StringselectFirstTextOrNull(String selector)Returns the node's text content, the node is located by selector. abstract List<String>selectTextAll(String selector)Returns a list of text contents of all the elements matching the specified selector within the page. abstract StringselectFirstAttributeOrNull(String selector, String attrName)Returns the node's attribute value, the node is located by selector, the attribute is attrName. abstract Map<String, String>selectAttributes(String selector)Returns the node's attribute values, the node is located by selector. abstract List<String>selectAttributeAll(String selector, String attrName, Integer start, Integer limit)Returns the nodes' attribute values, the nodes are located by selector, the attribute is attrName. abstract UnitsetAttribute(String selector, String attrName, String attrValue)Set the attribute of an element located by selector. abstract UnitsetAttributeAll(String selector, String attrName, String attrValue)Set the attribute of all elements matching selector. abstract StringselectFirstPropertyValueOrNull(String selector, String propName)Returns the node's property value, the node is located by selector, the property is propName. abstract List<String>selectPropertyValueAll(String selector, String propName, Integer start, Integer limit)Returns the nodes' property values, the nodes are located by selector, the property is propName. abstract UnitsetProperty(String selector, String propName, String propValue)Set the property of an element located by selector. abstract UnitsetPropertyAll(String selector, String propName, String propValue)Set the property of all elements matching selector. abstract List<Hyperlink>selectHyperlinks(String selector, Integer offset, Integer limit)Find hyperlinks in elements matching selector. abstract List<GeoAnchor>selectAnchors(String selector, Integer offset, Integer limit)Find anchor elements matching selector. abstract List<String>selectImages(String selector, Integer offset, Integer limit)Find image elements matching selector. abstract Objectevaluate(String expression)Executes JavaScript in the context of the currently selected frame or window. abstract <T extends Any> Tevaluate(String expression, T defaultValue)Executes JavaScript and returns the result, or defaultValue if the result is null or incompatible. abstract JsEvaluationevaluateDetail(String expression)returns detailed evaluation metadata (beta). abstract ObjectevaluateValue(String expression)Executes JavaScript and returns the result as a JSON-serializable value. abstract <T extends Any> TevaluateValue(String expression, T defaultValue)Executes JavaScript and returns the result as a JSON-serializable value, or defaultValue if null/incompatible. abstract ObjectevaluateValue(String selector, String functionDeclaration)Executes JavaScript for the element located by selector and returns the result as a JSON-serializable value. abstract JsEvaluationevaluateValueDetail(String expression)Returns detailed value evaluation metadata (beta). abstract JsEvaluationevaluateValueDetail(String selector, String functionDeclaration)Returns detailed value evaluation metadata for the element located by selector. abstract Stringscreenshot(Boolean fullPage)Capture a screenshot of the current viewport (or primary browsing context) after ensuring any pending layout. abstract Stringscreenshot(String selector)Scroll the element matched by selector into view (if needed) then take a screenshot of that element's bounding box. abstract Stringscreenshot(RectD rect)Take a screenshot of the rectangle specified by rect in the current page coordinate space. StringcaptureScreenshot(Boolean fullPage)StringcaptureScreenshot(String selector)StringcaptureScreenshot(RectD rect)abstract StringariaSnapshot()StringariaSnapshot(String viewports)Return the ARIA snapshot (accessibility tree in YAML format) for the specified viewports. abstract PointDclickablePoint(String selector)Calculate the clickable point of an element located by selector. abstract RectDboundingBox(String selector)Return the bounding box of an element located by selector. abstract ConnectionnewJsoupSession()Create a new Jsoup session with the last page's context, which means, the same headers and cookies. abstract Connection.ResponseloadJsoupResource(String url)Load the url as a resource with Jsoup rather than browser rendering, with the last page's context. abstract NetworkResourceResponseloadResource(String url)Load the url as a resource without browser rendering, with the last page's context. <Error class: unknown class>delay(Long millis)Delay for a given amount of time. <Error class: unknown class>delay(Duration duration)Delay for a given amount of time. <Error class: unknown class>delay(Duration duration)Delay for a given amount of time. abstract Unitupload(String selector, List<String> paths)Upload files to the element located by selector. abstract Unitpause()Force the page pauses all navigations and PENDING resource fetches. abstract Unitstop()Force the page stop all navigations and RELEASES all resources. abstract IntegergetId()The driver id, starts with 1. abstract IntegergetParentSid()The parent driver id. abstract StringgetGuid()The guid of the driver. abstract AbstractBrowsergetBrowser()The browser of the driver. abstract List<WebDriver>getFrames()Web pages for the page open from the current page, via window.open(), link click, form submission, etc. abstract WebDrivergetOpener()The driver from whom opens the current page. abstract Set<WebDriver>getOutgoingPages()Web pages for the page open from the current page, via window.open(), link click, form submission, etc. abstract BrowserTypegetBrowserType()The browser type. abstract NavigateEntrygetNavigateEntry()The current navigation entry. abstract UnitsetNavigateEntry(NavigateEntry navigateEntry)The current navigation entry. abstract NavigateHistorygetNavigateHistory()The navigation history. abstract Map<String, Object>getData()The associated data of the driver. abstract Map<String, IntRange>getDelayPolicy()The delay policy of the driver. abstract Map<String, Duration>getTimeoutPolicy()The timeout policy of the driver. -
-
Method Detail
-
addInitScript
abstract Unit addInitScript(String script)
Adds a script which would be evaluated whenever the page is navigated. @mcp
The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed Math.random.
This function should be invoked before a navigation, usually in an onWillNavigate event handler.
- Parameters:
script- JavaScript source code to add.
-
addBlockedURLs
abstract Unit addBlockedURLs(List<String> urlPatterns)
Blocks resource URLs from loading. @mcp
- Parameters:
urlPatterns- URL patterns to block.
-
open
Unit open(String url)
Opens the specified URL in the web driver. @mcp
This function navigates the web driver to the provided URL and waits for the navigation to complete. It is a suspend function, meaning it can be used within coroutines for asynchronous execution.
Example usage:
driver.open("https://www.example.com")- Parameters:
url- The URL to which the web driver should navigate.
-
navigate
abstract Unit navigate(String url)
Navigates current page to the given URL. @mcp
driver.navigate("https://www.example.com") driver.waitForNavigation()- Parameters:
url- URL to navigate page to.
-
navigate
abstract Unit navigate(NavigateEntry entry)
Navigates current page to the given URL. @mcp
val entry = NavigateEntry("https://www.example.com?timestamp=11712067353", pageUrl = "https://www.example.com") driver.navigate(entry) driver.waitForNavigation()- Parameters:
entry- NavigateEntry to navigate page to.
-
navigateTo
@Deprecated(message = "Use navigate(url: String) instead", replaceWith = @ReplaceWith(imports = {}, expression = "navigate(url)")) Unit navigateTo(String url)
-
reload
abstract Unit reload()
Reloads the current page. @mcp
This method should trigger a reload of the current page, similar to how a user would refresh the page in a browser.
-
goBack
abstract Unit goBack()
Navigates the browser to the previous page in the navigation history. @mcp
This method is expected to use the browser's navigation history to move back to the previous page. It should handle any exceptions that may occur during the navigation process.
-
goForward
abstract Unit goForward()
Navigates the browser to the next page in the navigation history. @mcp
This method is expected to use the browser's navigation history to move forward to the next page. It should handle any exceptions that may occur during the navigation process.
-
currentUrl
abstract String currentUrl()
Returns a string representing the current URL that the browser is looking at. @mcp
The current url is always the main frame's
document.documentURIif the browser succeed to return it, and is displayed in the browser's address bar.If the browser failed to return a proper url, returns the passed in url to navigate, just like a real user enter a url in the address bar but the browser failed to load the page.
NOTE: the url can be non-standard, for example:
about:blank chrome://newtab chrome://settings
see ai.platon.cdt.kt.protocol.types.page.NavigationEntry.userTypedURL
- Returns:
A string containing the URL of the document, or the passed in url to navigate.
-
url
abstract String url()
The URL read-only property of the Document interface returns the document location as a string. @mcp
This property equals to javascript
document.URL. Thedocument.URLproperty returns the same value. Thedocument.documentURIproperty can be used on any document types, while thedocument.URLproperty can only be used on HTML documents.- Returns:
A string containing the URL of the document
-
documentURI
abstract String documentURI()
Returns the document location as a string. @mcp
This property equals to javascript
document.documentURI.The
document.URLproperty which returns the same value. Thedocument.documentURIproperty can be used on any document types, while thedocument.URLproperty can only be used on HTML documents.- Returns:
The document's documentURI.
-
baseURI
abstract String baseURI()
Returns the document's baseURI. @mcp
The baseURI is a property of Node, it's the absolute base URL of the document containing the node. A baseURI is used to resolve relative URLs.
The base URL is determined as follows:
By default, the base URL is the location of the document (as determined by window.location).
If the document has an
<base>element, its href attribute is used.
- Returns:
The document's baseURI.
-
referrer
abstract String referrer()
The referrer property returns the URI of the page that linked to this page. @mcp
The value is an empty string if the user navigated to the page directly (not through a link, but, for example, by using a bookmark).
Inside an <iframe>, the referrer will initially be set to the same value as the href of the parent window's Window.location.
- Returns:
The document's referrer.
-
pageSource
abstract String pageSource()
Returns the source of the last loaded page. @mcp
If the page has been modified after loading (for example, by JavaScript) there is no guarantee that the returned text is that of the modified page.
PageSource and outerHTML:
pageSource: returns document HTML markup, will support non-HTML document
outerHTML: returns document HTML markup, for HTML document only
val pageSource = driver.pageSource()- Returns:
The source of the current page
-
nanoDOMTree
abstract <Error class: unknown class> nanoDOMTree()
Retrieves a lightweight version of the DOM tree (NanoDOMTree). @mcp
The NanoDOMTree is based on the accessibility tree and enhanced with DOM and document snapshot information. It is designed to be a compact representation suitable for AI processing and analysis.
- Returns:
A NanoDOMTree representing the current page state, or null if retrieval fails.
-
chat
abstract ModelResponse chat(String prompt, String selector)
Interact with an AI model using the context of the element selected by selector. @mcp
The AI model receives the element's content and structure as context along with the provided prompt.
- Parameters:
prompt- The question or instruction for the AI model.selector- The selector of the element, multiple formats supported.- Returns:
A ModelResponse containing the model's answer.
-
getCookies
abstract List<Map<String, String>> getCookies()
Returns the cookies of the current page. @mcp
val cookies = driver.getCookies()- Returns:
The cookies of the current page.
-
deleteCookies
abstract Unit deleteCookies(String name, String url, String domain, String path)
Deletes browser cookies with matching name and url or domain/path pair. @mcp
driver.deleteCookies("name", "https://www.example.com")NOTE: At least one of the url and domain needs to be specified
- Parameters:
name- Name of the cookies to remove.url- If specified, deletes all the cookies with the given name where domain and path match provided URL.domain- If specified, deletes only cookies with the exact domain.path- If specified, deletes only cookies with the exact path.
-
clearBrowserCookies
abstract Unit clearBrowserCookies()
Clears browser cookies. @mcp
driver.clearBrowserCookies()
-
waitForSelector
Duration waitForSelector(String selector)
Wait until the element identified by the selector becomes present in the DOM or timeout. @mcp
val remainingTime = driver.waitForSelector("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The remaining time until timeout when the element becomes present.
-
waitForSelector
Long waitForSelector(String selector, Long timeoutMillis)
Wait until the element identified by the selector becomes present in the DOM or timeout. @mcp
val remainingTime = driver.waitForSelector("h2.title", 30000)- Parameters:
selector- The selector of the element, multiple formats supported.timeoutMillis- The maximum time to wait for the element to become present.- Returns:
The remaining time until timeout when the element becomes present.
-
waitForSelector
Duration waitForSelector(String selector, Duration timeout)
Wait for the element identified by the selector to become present in the DOM, or until timeout. @mcp
val remainingTime = driver.waitForSelector("h2.title", Duration.ofSeconds(30))- Parameters:
selector- The selector of the element, multiple formats supported.timeout- The maximum time to wait for the element to become present.- Returns:
The remaining time until timeout when the element becomes present.
-
waitForSelector
abstract Duration waitForSelector(String selector, SuspendFunction0<Unit> action)
Wait for the element identified by the selector to become present in the DOM, or until timeout. @mcp
This method periodically checks for the existence of the element. If the element is not found during a check, the action will be executed, such as scrolling the page down.
val remainingTime = driver.waitForSelector("h2.title") { driver.scrollDown() }- Parameters:
selector- The selector of the element, multiple formats supported.action- The action to execute when the element is not found.
-
waitForSelector
Long waitForSelector(String selector, Long timeoutMillis, SuspendFunction0<Unit> action)
Wait for the element identified by the selector to become present in the DOM, or until timeout. @mcp
This method periodically checks for the existence of the element. If the element is not found during a check, the action will be executed, such as scrolling the page down.
val remainingTime = driver.waitForSelector("h2.title", 30000) { driver.scrollDown() }- Parameters:
selector- The selector of the element, multiple formats supported.timeoutMillis- The maximum time to wait for the element to become present.action- The action to execute when the element is not found.- Returns:
The remaining time until timeout when the element becomes present.
-
waitForSelector
abstract Duration waitForSelector(String selector, Duration timeout, SuspendFunction0<Unit> action)
Wait for the element identified by the selector to become present in the DOM, or until timeout. @mcp
This method periodically checks for the existence of the element. If the element is not found during a check, the action will be executed, such as scrolling the page down.
val remainingTime = driver.waitForSelector("h2.title", Duration.ofSeconds(30)) { driver.scrollDown() }- Parameters:
selector- The selector of the element, multiple formats supported.timeout- The maximum time to wait for the element to become present.action- The action to execute when the element is not found.- Returns:
The remaining time until timeout when the element becomes present.
-
waitForNavigation
abstract Duration waitForNavigation(String oldUrl)
Wait until the current url changes or timeout. @mcp
val url = "https://www.example.com" driver.navigate(url) var remainingTime = driver.waitForNavigation() if (remainingTime 0) { driver.click("a[href='/next']") remainingTime = driver.waitForNavigation(url) }
-
waitForNavigation
Long waitForNavigation(String oldUrl, Long timeoutMillis)
Wait until the current url changes or timeout. @mcp
val url = "https://www.example.com" driver.navigate(url) var remainingTime = driver.waitForNavigation(1000) if (remainingTime 0) { driver.click("a[href='/next']") remainingTime = driver.waitForNavigation(url, 1000) }- Parameters:
timeoutMillis- The maximum time to wait for the url to change.
-
waitForNavigation
abstract Duration waitForNavigation(String oldUrl, Duration timeout)
Wait until the current url changes or timeout. @mcp
val timeout = Duration.ofSeconds(30) val url = "https://www.example.com" driver.navigate(url) var remainingTime = driver.waitForNavigation(timeout) if (remainingTime 0) { driver.click("a[href='/next']") remainingTime = driver.waitForNavigation(url, timeout) }- Parameters:
timeout- The maximum time to wait for the url to change.
-
waitForPage
abstract WebDriver waitForPage(String url, Duration timeout)
Await navigation to the specified URL page or timeout if necessary. @mcp
val newDriver = driver.waitForPage("https://www.example.com", Duration.ofSeconds(30))TODO: check if waitForPage and waitForNavigation can be merged into one method.
- Parameters:
url- The URL to navigate to.- Returns:
The remaining time until timeout when the predicate returns true.
-
waitForFunction
abstract WebDriver waitForFunction(String pageFunction, Duration timeout)
Returns when the pageFunction returns a truthy value. @mcp
- Parameters:
pageFunction- A JavaScript function to be evaluated in the page context.
-
waitUntil
abstract Duration waitUntil(SuspendFunction0<Boolean> predicate)
Wait until the predicate returns true. @mcp
val remainingTime = driver.waitUntil { driver.exists("h2.title") }- Parameters:
predicate- The predicate to check.- Returns:
The remaining time until timeout when the predicate returns true.
-
waitUntil
Long waitUntil(Long timeoutMillis, SuspendFunction0<Boolean> predicate)
Wait until the predicate returns true. @mcp
val remainingTime = driver.waitUntil(10000) { driver.exists("h2.title") }- Parameters:
timeoutMillis- The maximum time to wait for the predicate to return true.predicate- The predicate to check.- Returns:
The remaining time until timeout when the predicate returns true.
-
waitUntil
abstract Duration waitUntil(Duration timeout, SuspendFunction0<Boolean> predicate)
Wait until the predicate returns true. @mcp
val remainingTime = driver.waitUntil(Duration.ofSeconds(10)) { driver.exists("h2.title") }- Parameters:
timeout- The maximum time to wait for the predicate to return true.predicate- The predicate to check.- Returns:
The remaining time until timeout when the predicate returns true.
-
exists
abstract Boolean exists(String selector)
Returns whether the element exists. @mcp
driver.exists("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
Whether the element exists.
-
isHidden
Boolean isHidden(String selector)
Returns whether the element is hidden. @mcp
driver.isHidden("input[name='q']")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
Whether the element is hidden.
-
isVisible
abstract Boolean isVisible(String selector)
Returns whether the element is visible. @mcp
driver.isVisible("input[name='q']")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
Whether the element is visible.
-
isChecked
abstract Boolean isChecked(String selector)
Returns whether the element is checked. @mcp
driver.isChecked("input[name='agree']")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
Whether the element is checked.
-
bringToFront
abstract Unit bringToFront()
Brings the browser window to the front. @mcp
driver.bringToFront()
-
hover
abstract Unit hover(String selector)
This method hovers over the element. @mcp
Scroll the element into view if needed.
Move mouse to hover over a random position near the center of the element.
driver.hover("h1")- Parameters:
selector- The selector of the element, multiple formats supported.
-
focus
abstract Unit focus(String selector)
This method fetches an element with
selectorand focuses it. @mcpIf there's no element matching
selector, nothing to do.driver.focus("input[name='q']")- Parameters:
selector- The selector of the element, multiple formats supported.
-
type
abstract Unit type(String text, String selector)
This method emulates inserting text that doesn't come from a key press. @mcp
driver.type("Hello, World!") driver.type("Hello, World!", "input[name='q']")When selector is omitted, text is typed into the currently focused element. When selector is provided, the matching element is focused first and then receives the text.
- Parameters:
text- The text to insert.selector- The selector of the element, multiple formats supported.
-
press
abstract Unit press(String key, String selector)
Shortcut for keyboard down and keyboard up. @mcp
The key is specified as a string, which can be a single character, a key name, or a combination of both. For example, 'a', 'A', 'KeyA', 'Enter', 'Shift+A', and 'Control+Shift+Tab' are all valid keys.
driver.press("Enter") driver.press("Enter", "input[name='q']")When selector is omitted, the key is pressed on the currently focused element. When selector is provided, the matching element is focused first and then receives the key press.
- Parameters:
key- A key to press.selector- The selector of the element, multiple formats supported.
-
fill
abstract Unit fill(String selector, String text)
This method emulates inserting text that doesn't come from a key press. @mcp
Unlike type, this method clears the existing value before typing.
driver.fill("input[name='q']", "Hello, World!")- Parameters:
selector- The selector of the element, multiple formats supported.text- The text to fill.
-
keyDown
abstract Unit keyDown(String key)
Presses and holds a keyboard key on the currently focused element. @mcp
driver.keyDown("Shift") driver.keyDown("Control")- Parameters:
key- A key to press and hold.
-
keyUp
abstract Unit keyUp(String key)
Releases a previously pressed keyboard key on the currently focused element. @mcp
driver.keyUp("Shift") driver.keyUp("Control")- Parameters:
key- A key to release.
-
click
abstract Unit click(String selector, Integer count)
Focus on an element with selector and click it. @mcp
If there's no element matching
selector, nothing to do.driver.click("button[type='submit']")- Parameters:
selector- The selector of the element, multiple formats supported.count- The number of times to click.
-
click
abstract Unit click(String selector, String modifier)
- Parameters:
selector- The selector of the element, multiple formats supported.modifier- The keyboard modifier to press while clicking (e.g., "Shift", "Control", "Alt").
-
dblclick
abstract Unit dblclick(String selector)
Focus on an element with selector and double-click it. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.
-
dblclick
abstract Unit dblclick(String selector, String modifier)
- Parameters:
selector- The selector of the element, multiple formats supported.modifier- The keyboard modifier to press while double-clicking.
-
resize
abstract Unit resize(Integer width, Integer height)
Resizes the viewport to the specified width and height. @mcp
-
dialogAccept
abstract Unit dialogAccept(String promptText)
Accepts the dialog. @mcp
-
dialogDismiss
abstract Unit dialogDismiss()
Dismisses the dialog. @mcp
-
clickTextMatches
abstract Unit clickTextMatches(String selector, String pattern, Integer count)
This method clicks an element with selector whose text content matches pattern, and then focuses it. @mcp
If there's no element matching selector, or the element's text content doesn't match pattern, nothing to do.
driver.clickTextMatches("button", "submit")TODO: use playwright style selector which supports text matching, for example:
button:has-text("submit")- Parameters:
selector- The selector of the element, multiple formats supported.pattern- The pattern to match the text content.count- The number of times to click.
-
clickMatches
abstract Unit clickMatches(String selector, String attrName, String pattern, Integer count)
This method clicks an element with selector whose attribute name is attrName and value matches pattern, and then focuses it. @mcp
If there's no element matching selector, or the element has no attribute attrName, or the element's attribute value doesn't match pattern, nothing to do.
driver.clickMatches("button", "type", "submit")- Parameters:
selector- The selector of the element, multiple formats supported.attrName- The attribute name to match.pattern- The pattern to match the attribute value.count- The number of times to click.
-
selectOption
abstract List<String> selectOption(String selector, List<String> values)
Selects one or more options in a <select> element. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.values- The values or labels of the options to select- Returns:
The list of selected option values
-
selectOption
String selectOption(String selector, String value)
Selects an option in a <select> element. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.value- The value or label of the option to select- Returns:
The selected option value, or null if not found
-
check
abstract Unit check(String selector)
This method check an element with selector. If there's no element matching selector, nothing to do. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.
-
uncheck
abstract Unit uncheck(String selector)
This method uncheck an element with selector. If there's no element matching selector, nothing to do. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.
-
scrollTo
abstract Double scrollTo(String selector)
This method fetches an element with selector, scrolls it into view if needed. @mcp
If there's no element matching selector, the method does nothing.
driver.scrollTo("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.
-
scrollDown
abstract Double scrollDown(Integer count)
The current page frame scrolls down for count times. @mcp
driver.scrollDown(3)TODO: use mouseWheel instead
- Parameters:
count- The times to scroll down.
-
scrollUp
abstract Double scrollUp(Integer count)
The current page frame scrolls up for count times. @mcp
driver.scrollUp(3)TODO: use mouseWheel instead
- Parameters:
count- The times to scroll up.
-
scrollBy
abstract Double scrollBy(Double pixels, Boolean smooth)
Scrolls the current page frame vertically by the given number of pixels. @mcp
Positive values scroll down, negative values scroll up. The target position is clamped to the scrollable range 0, scrollHeight - viewportHeight.
When smooth is true a deterministic, step‑wise scrolling algorithm is used (instead of relying on the browser's native smooth scrolling) for higher stability: it issues incremental
window.scrollTo()calls and waits for the viewport to settle after each step. This reduces race conditions with lazy‑loaded content or async layout changes and yields more predictable final positions.Typical usage:
// Scroll down 200px smoothly (default) driver.scrollBy() // Scroll up 500px immediately driver.scrollBy(-500.0, smooth = false) // Scroll down one viewport height, smooth val y = driver.scrollBy(driver.viewportHeight(), smooth = true)- Parameters:
pixels- The delta in pixels to scroll; positive scrolls down, negative scrolls up.smooth- Whether to perform a deterministic smooth scrolling sequence.- Returns:
The final vertical scroll offset (window.scrollY) after scrolling.
-
scrollToTop
abstract Double scrollToTop()
The current page frame scrolls to the top. @mcp
driver.scrollToTop()
-
scrollToBottom
abstract Double scrollToBottom()
The current page frame scrolls to the bottom. @mcp
driver.scrollToBottom()
-
scrollToMiddle
abstract Double scrollToMiddle(Double ratio)
The current page frame scrolls to the middle. @mcp
driver.scrollToMiddle(0.2) driver.scrollToMiddle(0.5) driver.scrollToMiddle(0.8)- Parameters:
ratio- The ratio of the page to scroll to, 0.0 means the top, 1.0 means the bottom.
-
scrollToViewport
abstract Double scrollToViewport(Double n, Boolean smooth)
Scroll to the 2.5th viewport position. @mcp
driver.scrollToViewport(1.0) driver.scrollToViewport(1.5) driver.scrollToViewport(2.5) driver.scrollToViewport(3.0)- Parameters:
n- The viewport number of the page to scroll to (1-based).
-
mouseWheel
abstract Unit mouseWheel(Double deltaX, Double deltaY)
Scrolls the mouse wheel by the provided deltas. @mcp
Positive deltaY scrolls down and negative deltaY scrolls up.
driver.mouseWheel(0.0, 150.0) driver.mouseWheel(0.0, -150.0)- Parameters:
deltaX- The distance to wheel horizontally.deltaY- The distance to wheel vertically.
-
mouseMove
abstract Unit mouseMove(Double x, Double y)
- Parameters:
x- The x coordinate to move to.y- The y coordinate to move to.
-
mouseDown
abstract Unit mouseDown(String button, Integer clickCount)
Presses a mouse button at the current mouse position. @mcp
driver.mouseDown() driver.mouseDown("right")- Parameters:
button- The mouse button to press.clickCount- The click count associated with the press event.
-
mouseUp
abstract Unit mouseUp(String button, Integer clickCount)
Releases a mouse button at the current mouse position. @mcp
driver.mouseUp() driver.mouseUp("right")- Parameters:
button- The mouse button to release.clickCount- The click count associated with the release event.
-
moveMouseTo
abstract Unit moveMouseTo(String selector, Integer deltaX, Integer deltaY)
The mouse moves to the element with selector. @mcp
driver.moveMouseTo("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.deltaX- The distance to the left of the element.deltaY- The distance to the top of the element.
-
dragAndDrop
abstract Unit dragAndDrop(String selector, Integer deltaX, Integer deltaY)
Performs a drag, dragenter, dragover, and drop in sequence. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.deltaX- The distance to drag horizontally.deltaY- The distance to drag vertically.
-
drag
Unit drag(String sourceSelector, String targetSelector)
Drags the element identified by sourceSelector onto the element identified by targetSelector. @mcp
The implementation dispatches an HTML5 drag sequence between the source and target elements using a shared
DataTransferpayload so selector-to-selector drag flows can be asserted reliably by automation clients.- Parameters:
sourceSelector- The selector of the element, multiple formats supported.targetSelector- The selector of the element, multiple formats supported.
-
outerHTML
abstract String outerHTML()
Returns the document's HTML markup. @mcp
val html = driver.outerHTML()If the document does not exist, returns null.
- Returns:
The HTML markup of the document.
-
outerHTML
abstract String outerHTML(String selector)
Returns the node's HTML markup, the node is located by selector. @mcp
If the node does not exist, returns null.
val html = driver.outerHTML("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The HTML markup of the node.
-
textContent
abstract String textContent(String selector)
Returns the text content of the document or a specific element. @mcp
If selector is null, returns the text content of the entire document (usually
document.body.innerText). If selector is provided, returns the text content of the first matching element.If the document or element does not exist, returns null.
val bodyText = driver.textContent() val titleText = driver.textContent("h1.title")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The text content, or null if not found.
-
extract
abstract Map<String, String> extract(Map<String, String> fields)
Extracts multiple fields from the page using CSS selectors. @mcp
- Parameters:
fields- A map where keys are field names and values are CSS selectors.- Returns:
A map containing the extracted text content for each field. Values are null if the selector matches nothing.
-
querySelectorAll
@Beta() abstract List<NodeRef> querySelectorAll(String selector)
Use querySelectorAll to get all elements matched by selector, and then return their NodeRefs. @mcp
Note that the NodeRefs may become stale after certain operations, so they should be used immediately after selection.
- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
a list of NodeRefs for the matched elements, or an empty list if no elements are matched or an error occurs.
-
selectFirstTextOrNull
abstract String selectFirstTextOrNull(String selector)
Returns the node's text content, the node is located by selector. @mcp
If the node does not exist, returns null.
val text = driver.selectFirstTextOrNull("h2.title")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The text content of the node.
-
selectTextAll
abstract List<String> selectTextAll(String selector)
Returns a list of text contents of all the elements matching the specified selector within the page. @mcp
If no elements match the selector, returns an empty list.
val texts = driver.selectTextAll("h2")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The text contents of the nodes.
-
selectFirstAttributeOrNull
abstract String selectFirstAttributeOrNull(String selector, String attrName)
Returns the node's attribute value, the node is located by selector, the attribute is attrName. @mcp
If the node does not exist, or the attribute does not exist, returns null.
val classes = driver.selectFirstAttributeOrNull("h2.title", "class")- Parameters:
selector- The selector of the element, multiple formats supported.attrName- The attribute name to retrieve.- Returns:
The attribute value of the node.
-
selectAttributes
abstract Map<String, String> selectAttributes(String selector)
Returns the node's attribute values, the node is located by selector. @mcp
If the node do not exist, or the attribute does not exist, returns an empty list.
val classes = driver.selectAttributes("h2.title", "class")- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The attribute pairs of the nodes.
-
selectAttributeAll
abstract List<String> selectAttributeAll(String selector, String attrName, Integer start, Integer limit)
Returns the nodes' attribute values, the nodes are located by selector, the attribute is attrName. @mcp
If the nodes do not exist, or the attribute does not exist, returns an empty list.
val classes = driver.selectAttributeAll("h2.title", "class")- Parameters:
selector- The selector of the element, multiple formats supported.attrName- The attribute name to retrieve.start- The offset of the first node to select.limit- The maximum number of nodes to select.- Returns:
The attribute values of the nodes.
-
setAttribute
abstract Unit setAttribute(String selector, String attrName, String attrValue)
Set the attribute of an element located by selector. @mcp
driver.setAttribute("h2.title", "class", "header")- Parameters:
selector- The selector of the element, multiple formats supported.attrName- The attribute name to set.attrValue- The attribute value to set.
-
setAttributeAll
abstract Unit setAttributeAll(String selector, String attrName, String attrValue)
Set the attribute of all elements matching selector. @mcp
driver.setAttributeAll("h2.title", "class", "header")- Parameters:
selector- The selector of the element, multiple formats supported.attrName- The attribute name to set.attrValue- The attribute value to set.
-
selectFirstPropertyValueOrNull
abstract String selectFirstPropertyValueOrNull(String selector, String propName)
Returns the node's property value, the node is located by selector, the property is propName. @mcp
If the node does not exist, or the property does not exist, returns null.
val classes = driver.selectFirstPropertyOrNull("input#input", "value")- Parameters:
selector- The selector of the element, multiple formats supported.propName- The property name to retrieve.- Returns:
The property value of the node.
-
selectPropertyValueAll
abstract List<String> selectPropertyValueAll(String selector, String propName, Integer start, Integer limit)
Returns the nodes' property values, the nodes are located by selector, the property is propName. @mcp
If the nodes do not exist, or the property does not exist, returns an empty list.
val classes = driver.selectPropertyAll("input#input", "value")- Parameters:
selector- The selector of the element, multiple formats supported.propName- The property name to retrieve.start- The offset of the first node to select.limit- The maximum number of nodes to select.- Returns:
The property values of the nodes.
-
setProperty
abstract Unit setProperty(String selector, String propName, String propValue)
Set the property of an element located by selector. @mcp
driver.setProperty("input#input", "value")- Parameters:
selector- The selector of the element, multiple formats supported.propName- The property name to set.propValue- The property value to set.
-
setPropertyAll
abstract Unit setPropertyAll(String selector, String propName, String propValue)
Set the property of all elements matching selector. @mcp
driver.setPropertyAll("input#input", "value")- Parameters:
selector- The selector of the element, multiple formats supported.propName- The property name to set.propValue- The property value to set.
-
selectHyperlinks
abstract List<Hyperlink> selectHyperlinks(String selector, Integer offset, Integer limit)
Find hyperlinks in elements matching selector.
val hyperlinks = driver.selectHyperlinks("a.product-link")- Parameters:
selector- The selector of the element, multiple formats supported.offset- The offset of the first element to select.limit- The maximum number of elements to select.- Returns:
The hyperlinks in the elements.
-
selectAnchors
abstract List<GeoAnchor> selectAnchors(String selector, Integer offset, Integer limit)
Find anchor elements matching selector.
val anchors = driver.selectAnchors("a.product-link")- Parameters:
selector- The selector of the element, multiple formats supported.offset- The offset of the first element to select.limit- The maximum number of elements to select.- Returns:
The anchors.
-
selectImages
abstract List<String> selectImages(String selector, Integer offset, Integer limit)
Find image elements matching selector.
val images = driver.selectImages("img.product-image")- Parameters:
selector- The selector of the element, multiple formats supported.offset- The offset of the first element to select.limit- The maximum number of elements to select.- Returns:
The image URLs.
-
evaluate
abstract Object evaluate(String expression)
Executes JavaScript in the context of the currently selected frame or window. @mcp
If the result is not JavaScript object, it is not returned.
If you want to execute a function, convert it to IIFE (Immediately Invoked Function Expression).
val title = driver.evaluate("document.title")Multi-line JavaScript code:
val code = """ () => { const a = 10; const b = 20; return a * b; } """.trimIndent() val result = driver.evaluate(code)Wrap the code in an IIFE (Immediately Invoked Function Expression) to return a value.
Escape line breaks with
\n.
- Parameters:
expression- JavaScript expression to evaluate- Returns:
Remote object value in case of primitive values or null.
-
evaluate
abstract <T extends Any> T evaluate(String expression, T defaultValue)
Executes JavaScript and returns the result, or defaultValue if the result is null or incompatible. @mcp
- Parameters:
expression- The JavaScript expression to evaluate.defaultValue- The value to return if evaluation fails or returns null.- Returns:
The evaluation result or defaultValue.
-
evaluateDetail
abstract JsEvaluation evaluateDetail(String expression)
returns detailed evaluation metadata (beta). @mcp
- Parameters:
expression- The JavaScript expression to evaluate.- Returns:
A JsEvaluation object containing the result and metadata.
-
evaluateValue
abstract Object evaluateValue(String expression)
Executes JavaScript and returns the result as a JSON-serializable value. @mcp
If the result is an object, it is serialized to a Map or List. If the result is a primitive, it is returned as is. If the result is null or undefined, null is returned.
- Parameters:
expression- The JavaScript expression to evaluate.- Returns:
The result as a JSON-compatible object (Map, List, String, Number, Boolean, or null).
-
evaluateValue
abstract <T extends Any> T evaluateValue(String expression, T defaultValue)
Executes JavaScript and returns the result as a JSON-serializable value, or defaultValue if null/incompatible. @mcp
- Parameters:
expression- The JavaScript expression to evaluate.defaultValue- The value to return if evaluation fails or returns null.- Returns:
The evaluation result or defaultValue.
-
evaluateValue
abstract Object evaluateValue(String selector, String functionDeclaration)
Executes JavaScript for the element located by selector and returns the result as a JSON-serializable value. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.functionDeclaration- The JavaScript function declaration to execute against the matched element.- Returns:
The result as a JSON-compatible object (Map, List, String, Number, Boolean, or null).
-
evaluateValueDetail
abstract JsEvaluation evaluateValueDetail(String expression)
Returns detailed value evaluation metadata (beta). @mcp
- Parameters:
expression- The JavaScript expression to evaluate.- Returns:
A JsEvaluation object containing the result value and metadata.
-
evaluateValueDetail
abstract JsEvaluation evaluateValueDetail(String selector, String functionDeclaration)
Returns detailed value evaluation metadata for the element located by selector. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.functionDeclaration- The JavaScript function declaration to execute against the matched element.- Returns:
A JsEvaluation object containing the result value and metadata.
-
screenshot
abstract String screenshot(Boolean fullPage)
Capture a screenshot of the current viewport (or primary browsing context) after ensuring any pending layout. @mcp
If the backend supports element-centric capture this may represent the full page; implementation specific.
The target element (if any) is scrolled into view before capture.
val base64 = driver.screenshot() val bytes = Base64.getDecoder().decode(base64)
-
screenshot
abstract String screenshot(String selector)
Scroll the element matched by selector into view (if needed) then take a screenshot of that element's bounding box. @mcp
Returns a Base64 encoded image (implementation usually PNG/JPEG), PNG by default.
- Parameters:
selector- The selector of the element, multiple formats supported.
-
screenshot
abstract String screenshot(RectD rect)
Take a screenshot of the rectangle specified by rect in the current page coordinate space. @mcp
Caller is responsible for ensuring the rectangle is visible or scrolled into view if the implementation requires it.
-
captureScreenshot
@Deprecated(message = "Use screenshot(fullPage = true) instead", replaceWith = @ReplaceWith(imports = {}, expression = "screenshot(fullPage = true)")) String captureScreenshot(Boolean fullPage)
-
captureScreenshot
@Deprecated(message = "Use screenshot(selector) instead", replaceWith = @ReplaceWith(imports = {}, expression = "screenshot(selector)")) String captureScreenshot(String selector)
-
captureScreenshot
@Deprecated(message = "Use screenshot(rect) instead", replaceWith = @ReplaceWith(imports = {}, expression = "screenshot(rect)")) String captureScreenshot(RectD rect)
-
ariaSnapshot
abstract String ariaSnapshot()
-
ariaSnapshot
String ariaSnapshot(String viewports)
Return the ARIA snapshot (accessibility tree in YAML format) for the specified viewports. @mcp
The viewports parameter controls which viewport(s) to include:
"all"— return the full-page snapshot (default)."3"— return only viewport 3."1,3,5"— return viewports 1, 3 and 5."2-4"— return viewports 2, 3 and 4.
Viewport indices are 1-based. The viewport height is determined by the browser's current viewport dimensions.
- Parameters:
viewports- A viewport specification string (e.g.- Returns:
The ARIA snapshot YAML covering only the requested viewports.
-
clickablePoint
abstract PointD clickablePoint(String selector)
Calculate the clickable point of an element located by selector. @mcp
If the element does not exist, or is not clickable, returns null.
- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The clickable point of the element.
-
boundingBox
abstract RectD boundingBox(String selector)
Return the bounding box of an element located by selector. @mcp
If the element does not exist, returns null.
- Parameters:
selector- The selector of the element, multiple formats supported.- Returns:
The bounding box of the element.
-
newJsoupSession
abstract Connection newJsoupSession()
Create a new Jsoup session with the last page's context, which means, the same headers and cookies. @mcp
- Returns:
The Jsoup session.
-
loadJsoupResource
abstract Connection.Response loadJsoupResource(String url)
Load the url as a resource with Jsoup rather than browser rendering, with the last page's context. @mcp
This means, the same headers and cookies.
- Parameters:
url- The URL to load.- Returns:
The Jsoup response.
-
loadResource
abstract NetworkResourceResponse loadResource(String url)
Load the url as a resource without browser rendering, with the last page's context. @mcp
This means, the same headers and cookies.
- Parameters:
url- The URL to load.- Returns:
The network resource response.
-
delay
<Error class: unknown class> delay(Long millis)
Delay for a given amount of time. @mcp
- Parameters:
millis- The amount of time to delay, in milliseconds.
-
delay
<Error class: unknown class> delay(Duration duration)
Delay for a given amount of time. @mcp
- Parameters:
duration- The amount of time to delay.
-
delay
<Error class: unknown class> delay(Duration duration)
Delay for a given amount of time. @mcp
- Parameters:
duration- The amount of time to delay.
-
upload
abstract Unit upload(String selector, List<String> paths)
Upload files to the element located by selector. @mcp
- Parameters:
selector- The selector of the element, multiple formats supported.paths- The list of file paths to upload.
-
pause
abstract Unit pause()
Force the page pauses all navigations and PENDING resource fetches. @mcp
If the page loading pauses, the user can still interact with the page, and therefore resources can continue to load.
-
stop
abstract Unit stop()
Force the page stop all navigations and RELEASES all resources. @mcp
Interaction with the stop page results in undefined behavior and the results should not be trusted.
If a web driver stops, it can later be used to visit other pages.
-
getParentSid
abstract Integer getParentSid()
The parent driver id. The id is unique in process scope.
-
getBrowser
abstract AbstractBrowser getBrowser()
The browser of the driver. The browser defines methods and events to manipulate a real browser.
-
getFrames
abstract List<WebDriver> getFrames()
Web pages for the page open from the current page, via window.open(), link click, form submission, etc.
TODO: NOT IMPLEMENTED
-
getOutgoingPages
abstract Set<WebDriver> getOutgoingPages()
Web pages for the page open from the current page, via window.open(), link click, form submission, etc.
-
getBrowserType
abstract BrowserType getBrowserType()
The browser type. BrowserType.PULSAR_CHROME is the only fully supported browser type currently. BrowserType.PLAYWRIGHT_CHROME is a partially supported browser type since Playwright is not thread safe.
-
getNavigateEntry
abstract NavigateEntry getNavigateEntry()
The current navigation entry.
-
setNavigateEntry
abstract Unit setNavigateEntry(NavigateEntry navigateEntry)
The current navigation entry.
-
getNavigateHistory
abstract NavigateHistory getNavigateHistory()
The navigation history.
-
getDelayPolicy
abstract Map<String, IntRange> getDelayPolicy()
The delay policy of the driver. The delay policy is a map of delay ranges in milliseconds for different actions.
The delay policy is used to simulate human behaviors, such as typing, clicking, scrolling, etc.
delayPolicy["click"] == 500..1000
-
getTimeoutPolicy
abstract Map<String, Duration> getTimeoutPolicy()
The timeout policy of the driver. The timeout policy is a map of timeout durations for different actions.
The timeout policy is used to set the maximum time to wait for an action to complete.
timeoutPolicy["click"] == Duration.ofSeconds(30)
-
-
-
-