public interface Frame
Page.mainFrame() and Frame.childFrames() methods.
Frame object's lifecycle is controlled by three events, dispatched on the page object:
Page.onFrameAttached() - fired when the frame gets attached to the page. A Frame can be
attached to the page only once.Page.onFrameNavigated() - fired when the frame commits navigation to a different URL.Page.onFrameDetached() - fired when the frame gets detached from the page. A Frame can be
detached from the page only once.An example of dumping frame tree:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType firefox = playwright.firefox();
Browser browser = firefox.launch();
Page page = browser.newPage();
page.navigate("https://www.google.com/chrome/browser/canary.html");
dumpFrameTree(page.mainFrame(), "");
browser.close();
}
}
static void dumpFrameTree(Frame frame, String indent) {
System.out.println(indent + frame.url());
for (Frame child : frame.childFrames()) {
dumpFrameTree(child, indent + " ");
}
}
}
| Modifier and Type | Method and Description |
|---|---|
default ElementHandle |
addScriptTag()
Returns the added tag when the script's onload fires or when the script content was injected into frame.
|
ElementHandle |
addScriptTag(Frame.AddScriptTagOptions options)
Returns the added tag when the script's onload fires or when the script content was injected into frame.
|
default ElementHandle |
addStyleTag()
Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
|
ElementHandle |
addStyleTag(Frame.AddStyleTagOptions options)
Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
|
default void |
check(String selector)
This method checks an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
check(String selector,
Frame.CheckOptions options)
This method checks an element matching
selector by performing the following steps:
Find an element matching selector. |
List<Frame> |
childFrames() |
default void |
click(String selector)
This method clicks an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
click(String selector,
Frame.ClickOptions options)
This method clicks an element matching
selector by performing the following steps:
Find an element matching selector. |
String |
content()
Gets the full HTML contents of the frame, including the doctype.
|
default void |
dblclick(String selector)
This method double clicks an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
dblclick(String selector,
Frame.DblclickOptions options)
This method double clicks an element matching
selector by performing the following steps:
Find an element matching selector. |
default void |
dispatchEvent(String selector,
String type)
The snippet below dispatches the
click event on the element. |
default void |
dispatchEvent(String selector,
String type,
Object eventInit)
The snippet below dispatches the
click event on the element. |
void |
dispatchEvent(String selector,
String type,
Object eventInit,
Frame.DispatchEventOptions options)
The snippet below dispatches the
click event on the element. |
default Object |
evalOnSelector(String selector,
String expression)
Returns the return value of
expression. |
Object |
evalOnSelector(String selector,
String expression,
Object arg)
Returns the return value of
expression. |
default Object |
evalOnSelectorAll(String selector,
String expression)
Returns the return value of
expression. |
Object |
evalOnSelectorAll(String selector,
String expression,
Object arg)
Returns the return value of
expression. |
default Object |
evaluate(String expression)
Returns the return value of
expression. |
Object |
evaluate(String expression,
Object arg)
Returns the return value of
expression. |
default JSHandle |
evaluateHandle(String expression)
Returns the return value of
expression as a JSHandle. |
JSHandle |
evaluateHandle(String expression,
Object arg)
Returns the return value of
expression as a JSHandle. |
default void |
fill(String selector,
String value)
This method waits for an element matching
selector, waits for actionability checks, focuses the element, fills it and
triggers an input event after filling. |
void |
fill(String selector,
String value,
Frame.FillOptions options)
This method waits for an element matching
selector, waits for actionability checks, focuses the element, fills it and
triggers an input event after filling. |
default void |
focus(String selector)
This method fetches an element with
selector and focuses it. |
void |
focus(String selector,
Frame.FocusOptions options)
This method fetches an element with
selector and focuses it. |
ElementHandle |
frameElement()
Returns the
frame or iframe element handle which corresponds to this frame. |
default String |
getAttribute(String selector,
String name)
Returns element attribute value.
|
String |
getAttribute(String selector,
String name,
Frame.GetAttributeOptions options)
Returns element attribute value.
|
default void |
hover(String selector)
This method hovers over an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
hover(String selector,
Frame.HoverOptions options)
This method hovers over an element matching
selector by performing the following steps:
Find an element matching selector. |
default String |
innerHTML(String selector)
Returns
element.innerHTML. |
String |
innerHTML(String selector,
Frame.InnerHTMLOptions options)
Returns
element.innerHTML. |
default String |
innerText(String selector)
Returns
element.innerText. |
String |
innerText(String selector,
Frame.InnerTextOptions options)
Returns
element.innerText. |
default boolean |
isChecked(String selector)
Returns whether the element is checked.
|
boolean |
isChecked(String selector,
Frame.IsCheckedOptions options)
Returns whether the element is checked.
|
boolean |
isDetached()
Returns
true if the frame has been detached, or false otherwise. |
default boolean |
isDisabled(String selector)
Returns whether the element is disabled, the opposite of enabled.
|
boolean |
isDisabled(String selector,
Frame.IsDisabledOptions options)
Returns whether the element is disabled, the opposite of enabled.
|
default boolean |
isEditable(String selector)
Returns whether the element is editable.
|
boolean |
isEditable(String selector,
Frame.IsEditableOptions options)
Returns whether the element is editable.
|
default boolean |
isEnabled(String selector)
Returns whether the element is enabled.
|
boolean |
isEnabled(String selector,
Frame.IsEnabledOptions options)
Returns whether the element is enabled.
|
default boolean |
isHidden(String selector)
Returns whether the element is hidden, the opposite of visible.
|
boolean |
isHidden(String selector,
Frame.IsHiddenOptions options)
Returns whether the element is hidden, the opposite of visible.
|
default boolean |
isVisible(String selector)
Returns whether the element is visible.
|
boolean |
isVisible(String selector,
Frame.IsVisibleOptions options)
Returns whether the element is visible.
|
String |
name()
Returns frame's name attribute as specified in the tag.
|
default Response |
navigate(String url)
Returns the main resource response.
|
Response |
navigate(String url,
Frame.NavigateOptions options)
Returns the main resource response.
|
Page |
page()
Returns the page containing this frame.
|
Frame |
parentFrame()
Parent frame, if any.
|
default void |
press(String selector,
String key)
key can specify the intended keyboardEvent.key value or a single
character to generate the text for. |
void |
press(String selector,
String key,
Frame.PressOptions options)
key can specify the intended keyboardEvent.key value or a single
character to generate the text for. |
ElementHandle |
querySelector(String selector)
Returns the ElementHandle pointing to the frame element.
|
List<ElementHandle> |
querySelectorAll(String selector)
Returns the ElementHandles pointing to the frame elements.
|
default List<String> |
selectOption(String selector,
ElementHandle values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default List<String> |
selectOption(String selector,
ElementHandle[] values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
ElementHandle[] values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
ElementHandle values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default List<String> |
selectOption(String selector,
SelectOption values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default List<String> |
selectOption(String selector,
SelectOption[] values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
SelectOption[] values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
SelectOption values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default List<String> |
selectOption(String selector,
String values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default List<String> |
selectOption(String selector,
String[] values)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
String[] values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
List<String> |
selectOption(String selector,
String values,
Frame.SelectOptionOptions options)
This method waits for an element matching
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options. |
default void |
setContent(String html) |
void |
setContent(String html,
Frame.SetContentOptions options) |
default void |
setInputFiles(String selector,
FilePayload files)
This method expects
selector to point to an input element. |
default void |
setInputFiles(String selector,
FilePayload[] files)
This method expects
selector to point to an input element. |
void |
setInputFiles(String selector,
FilePayload[] files,
Frame.SetInputFilesOptions options)
This method expects
selector to point to an input element. |
void |
setInputFiles(String selector,
FilePayload files,
Frame.SetInputFilesOptions options)
This method expects
selector to point to an input element. |
default void |
setInputFiles(String selector,
Path files)
This method expects
selector to point to an input element. |
default void |
setInputFiles(String selector,
Path[] files)
This method expects
selector to point to an input element. |
void |
setInputFiles(String selector,
Path[] files,
Frame.SetInputFilesOptions options)
This method expects
selector to point to an input element. |
void |
setInputFiles(String selector,
Path files,
Frame.SetInputFilesOptions options)
This method expects
selector to point to an input element. |
default void |
tap(String selector)
This method taps an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
tap(String selector,
Frame.TapOptions options)
This method taps an element matching
selector by performing the following steps:
Find an element matching selector. |
default String |
textContent(String selector)
Returns
element.textContent. |
String |
textContent(String selector,
Frame.TextContentOptions options)
Returns
element.textContent. |
String |
title()
Returns the page title.
|
default void |
type(String selector,
String text)
Sends a
keydown, keypress/input, and keyup event for each character in the text. |
void |
type(String selector,
String text,
Frame.TypeOptions options)
Sends a
keydown, keypress/input, and keyup event for each character in the text. |
default void |
uncheck(String selector)
This method checks an element matching
selector by performing the following steps:
Find an element matching selector. |
void |
uncheck(String selector,
Frame.UncheckOptions options)
This method checks an element matching
selector by performing the following steps:
Find an element matching selector. |
String |
url()
Returns frame's url.
|
default JSHandle |
waitForFunction(String expression)
Returns when the
expression returns a truthy value, returns that value. |
default JSHandle |
waitForFunction(String expression,
Object arg)
Returns when the
expression returns a truthy value, returns that value. |
JSHandle |
waitForFunction(String expression,
Object arg,
Frame.WaitForFunctionOptions options)
Returns when the
expression returns a truthy value, returns that value. |
default void |
waitForLoadState()
Waits for the required load state to be reached.
|
default void |
waitForLoadState(LoadState state)
Waits for the required load state to be reached.
|
void |
waitForLoadState(LoadState state,
Frame.WaitForLoadStateOptions options)
Waits for the required load state to be reached.
|
Response |
waitForNavigation(Frame.WaitForNavigationOptions options,
Runnable callback)
Waits for the frame navigation and returns the main resource response.
|
default Response |
waitForNavigation(Runnable callback)
Waits for the frame navigation and returns the main resource response.
|
default ElementHandle |
waitForSelector(String selector)
Returns when element specified by selector satisfies
state option. |
ElementHandle |
waitForSelector(String selector,
Frame.WaitForSelectorOptions options)
Returns when element specified by selector satisfies
state option. |
void |
waitForTimeout(double timeout)
Waits for the given
timeout in milliseconds. |
default void |
waitForURL(Pattern url)
Waits for the frame to navigate to the given URL.
|
void |
waitForURL(Pattern url,
Frame.WaitForURLOptions options)
Waits for the frame to navigate to the given URL.
|
default void |
waitForURL(Predicate<String> url)
Waits for the frame to navigate to the given URL.
|
void |
waitForURL(Predicate<String> url,
Frame.WaitForURLOptions options)
Waits for the frame to navigate to the given URL.
|
default void |
waitForURL(String url)
Waits for the frame to navigate to the given URL.
|
void |
waitForURL(String url,
Frame.WaitForURLOptions options)
Waits for the frame to navigate to the given URL.
|
default ElementHandle addScriptTag()
Adds a <script> tag into the page with the desired url or content.
ElementHandle addScriptTag(Frame.AddScriptTagOptions options)
Adds a <script> tag into the page with the desired url or content.
default ElementHandle addStyleTag()
Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the
content.
ElementHandle addStyleTag(Frame.AddStyleTagOptions options)
Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the
content.
default void check(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void check(String selector, Frame.CheckOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void click(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void click(String selector, Frame.ClickOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String content()
default void dblclick(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to double click in the center of the element, or the specified position.noWaitAfter option is set. Note that if the first
click of the dblclick() triggers a navigation event, this method will throw. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
NOTE: frame.dblclick() dispatches two click events and a single dblclick event.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void dblclick(String selector, Frame.DblclickOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to double click in the center of the element, or the specified position.noWaitAfter option is set. Note that if the first
click of the dblclick() triggers a navigation event, this method will throw. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
NOTE: frame.dblclick() dispatches two click events and a single dblclick event.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void dispatchEvent(String selector, String type, Object eventInit)
click event on the element. Regardless of the visibility state of the element,
click is dispatched. This is equivalent to calling element.click().
frame.dispatchEvent("button#submit", "click");
Under the hood, it creates an instance of an event based on the given type, initializes it with eventInit properties
and dispatches it on the element. Events are composed, cancelable and bubble by default.
Since eventInit is event-specific, please refer to the events documentation for the lists of initial properties:
You can also specify JSHandle as the property value if you want live objects to be passed into the event:
// Note you can only create DataTransfer in Chromium and Firefox
JSHandle dataTransfer = frame.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
frame.dispatchEvent("#source", "dragstart", arg);
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.type - DOM event type: "click", "dragstart", etc.eventInit - Optional event-specific initialization properties.default void dispatchEvent(String selector, String type)
click event on the element. Regardless of the visibility state of the element,
click is dispatched. This is equivalent to calling element.click().
frame.dispatchEvent("button#submit", "click");
Under the hood, it creates an instance of an event based on the given type, initializes it with eventInit properties
and dispatches it on the element. Events are composed, cancelable and bubble by default.
Since eventInit is event-specific, please refer to the events documentation for the lists of initial properties:
You can also specify JSHandle as the property value if you want live objects to be passed into the event:
// Note you can only create DataTransfer in Chromium and Firefox
JSHandle dataTransfer = frame.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
frame.dispatchEvent("#source", "dragstart", arg);
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.type - DOM event type: "click", "dragstart", etc.void dispatchEvent(String selector, String type, Object eventInit, Frame.DispatchEventOptions options)
click event on the element. Regardless of the visibility state of the element,
click is dispatched. This is equivalent to calling element.click().
frame.dispatchEvent("button#submit", "click");
Under the hood, it creates an instance of an event based on the given type, initializes it with eventInit properties
and dispatches it on the element. Events are composed, cancelable and bubble by default.
Since eventInit is event-specific, please refer to the events documentation for the lists of initial properties:
You can also specify JSHandle as the property value if you want live objects to be passed into the event:
// Note you can only create DataTransfer in Chromium and Firefox
JSHandle dataTransfer = frame.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
frame.dispatchEvent("#source", "dragstart", arg);
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.type - DOM event type: "click", "dragstart", etc.eventInit - Optional event-specific initialization properties.default Object evalOnSelector(String selector, String expression)
expression.
The method finds an element matching the specified selector within the frame and passes it as a first argument to
expression. See Working with selectors for more details. If
no elements match the selector, the method throws an error.
If expression returns a Promise, then Frame.evalOnSelector() would wait for the promise to resolve and return its value.
Examples:
String searchValue = (String) frame.evalOnSelector("#search", "el => el.value");
String preloadHref = (String) frame.evalOnSelector("link[rel=preload]", "el => el.href");
String html = (String) frame.evalOnSelector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
selector - A selector to query for. See working with selectors for more
details.expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.Object evalOnSelector(String selector, String expression, Object arg)
expression.
The method finds an element matching the specified selector within the frame and passes it as a first argument to
expression. See Working with selectors for more details. If
no elements match the selector, the method throws an error.
If expression returns a Promise, then Frame.evalOnSelector() would wait for the promise to resolve and return its value.
Examples:
String searchValue = (String) frame.evalOnSelector("#search", "el => el.value");
String preloadHref = (String) frame.evalOnSelector("link[rel=preload]", "el => el.href");
String html = (String) frame.evalOnSelector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
selector - A selector to query for. See working with selectors for more
details.expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default Object evalOnSelectorAll(String selector, String expression)
expression.
The method finds all elements matching the specified selector within the frame and passes an array of matched elements
as a first argument to expression. See Working with
selectors for more details.
If expression returns a Promise, then Frame.evalOnSelectorAll() would wait for the promise to resolve and return its value.
Examples:
boolean divsCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
selector - A selector to query for. See working with selectors for more
details.expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.Object evalOnSelectorAll(String selector, String expression, Object arg)
expression.
The method finds all elements matching the specified selector within the frame and passes an array of matched elements
as a first argument to expression. See Working with
selectors for more details.
If expression returns a Promise, then Frame.evalOnSelectorAll() would wait for the promise to resolve and return its value.
Examples:
boolean divsCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
selector - A selector to query for. See working with selectors for more
details.expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default Object evaluate(String expression)
expression.
If the function passed to the Frame.evaluate() returns a Promise, then Frame.evaluate() would wait for the promise to resolve and return its value.
If the function passed to the Frame.evaluate() returns a non-[Serializable] value, then Frame.evaluate() returns undefined. Playwright also supports transferring some additional values that
are not serializable by JSON: -0, NaN, Infinity, -Infinity.
Object result = frame.evaluate("([x, y]) => {\n" +
" return Promise.resolve(x * y);\n" +
"}", Arrays.asList(7, 8));
System.out.println(result); // prints "56"
A string can also be passed in instead of a function.
System.out.println(frame.evaluate("1 + 2")); // prints "3"
ElementHandle instances can be passed as an argument to the Frame.evaluate():
ElementHandle bodyHandle = frame.querySelector("body");
String html = (String) frame.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
bodyHandle.dispose();
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.Object evaluate(String expression, Object arg)
expression.
If the function passed to the Frame.evaluate() returns a Promise, then Frame.evaluate() would wait for the promise to resolve and return its value.
If the function passed to the Frame.evaluate() returns a non-[Serializable] value, then Frame.evaluate() returns undefined. Playwright also supports transferring some additional values that
are not serializable by JSON: -0, NaN, Infinity, -Infinity.
Object result = frame.evaluate("([x, y]) => {\n" +
" return Promise.resolve(x * y);\n" +
"}", Arrays.asList(7, 8));
System.out.println(result); // prints "56"
A string can also be passed in instead of a function.
System.out.println(frame.evaluate("1 + 2")); // prints "3"
ElementHandle instances can be passed as an argument to the Frame.evaluate():
ElementHandle bodyHandle = frame.querySelector("body");
String html = (String) frame.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
bodyHandle.dispose();
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default JSHandle evaluateHandle(String expression)
expression as a JSHandle.
The only difference between Frame.evaluate() and Frame.evaluateHandle() is that Frame.evaluateHandle() returns JSHandle.
If the function, passed to the Frame.evaluateHandle(), returns a Promise, then Frame.evaluateHandle() would wait for the promise to resolve and return its value.
// Handle for the window object.
JSHandle aWindowHandle = frame.evaluateHandle("() => Promise.resolve(window)");
A string can also be passed in instead of a function.
JSHandle aHandle = frame.evaluateHandle("document"); // Handle for the "document".
JSHandle instances can be passed as an argument to the Frame.evaluateHandle():
JSHandle aHandle = frame.evaluateHandle("() => document.body");
JSHandle resultHandle = frame.evaluateHandle("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(aHandle, "hello"));
System.out.println(resultHandle.jsonValue());
resultHandle.dispose();
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.JSHandle evaluateHandle(String expression, Object arg)
expression as a JSHandle.
The only difference between Frame.evaluate() and Frame.evaluateHandle() is that Frame.evaluateHandle() returns JSHandle.
If the function, passed to the Frame.evaluateHandle(), returns a Promise, then Frame.evaluateHandle() would wait for the promise to resolve and return its value.
// Handle for the window object.
JSHandle aWindowHandle = frame.evaluateHandle("() => Promise.resolve(window)");
A string can also be passed in instead of a function.
JSHandle aHandle = frame.evaluateHandle("document"); // Handle for the "document".
JSHandle instances can be passed as an argument to the Frame.evaluateHandle():
JSHandle aHandle = frame.evaluateHandle("() => document.body");
JSHandle resultHandle = frame.evaluateHandle("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(aHandle, "hello"));
System.out.println(resultHandle.jsonValue());
resultHandle.dispose();
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default void fill(String selector, String value)
selector, waits for actionability checks, focuses the element, fills it and
triggers an input event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an <input>, <textarea> or [contenteditable] element, this method throws an error.
However, if the element is inside the <label> element that has an associated control, the control will be filled
instead.
To send fine-grained keyboard events, use Frame.type().
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.value - Value to fill for the <input>, <textarea> or [contenteditable] element.void fill(String selector, String value, Frame.FillOptions options)
selector, waits for actionability checks, focuses the element, fills it and
triggers an input event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an <input>, <textarea> or [contenteditable] element, this method throws an error.
However, if the element is inside the <label> element that has an associated control, the control will be filled
instead.
To send fine-grained keyboard events, use Frame.type().
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.value - Value to fill for the <input>, <textarea> or [contenteditable] element.default void focus(String selector)
selector and focuses it. If there's no element matching selector, the method
waits until a matching element appears in the DOM.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void focus(String selector, Frame.FocusOptions options)
selector and focuses it. If there's no element matching selector, the method
waits until a matching element appears in the DOM.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.ElementHandle frameElement()
frame or iframe element handle which corresponds to this frame.
This is an inverse of ElementHandle.contentFrame(). Note that returned handle
actually belongs to the parent frame.
This method throws an error if the frame has been detached before frameElement() returns.
ElementHandle frameElement = frame.frameElement();
Frame contentFrame = frameElement.contentFrame();
System.out.println(frame == contentFrame); // -> true
default String getAttribute(String selector, String name)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.name - Attribute name to get the value for.String getAttribute(String selector, String name, Frame.GetAttributeOptions options)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.name - Attribute name to get the value for.default Response navigate(String url)
frame.goto will throw an error if:
timeout is exceeded during navigation. frame.goto will not throw an error when any valid HTTP status code is returned by the remote server, including 404
"Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling Response.status().
NOTE: frame.goto either throws an error or returns a main resource response. The only exceptions are navigation to
about:blank or navigation to the same URL with a different hash, which would succeed and return null.
NOTE: Headless mode doesn't support navigation to a PDF document. See the upstream issue.
url - URL to navigate frame to. The url should include scheme, e.g. https://.Response navigate(String url, Frame.NavigateOptions options)
frame.goto will throw an error if:
timeout is exceeded during navigation. frame.goto will not throw an error when any valid HTTP status code is returned by the remote server, including 404
"Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling Response.status().
NOTE: frame.goto either throws an error or returns a main resource response. The only exceptions are navigation to
about:blank or navigation to the same URL with a different hash, which would succeed and return null.
NOTE: Headless mode doesn't support navigation to a PDF document. See the upstream issue.
url - URL to navigate frame to. The url should include scheme, e.g. https://.default void hover(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to hover over the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void hover(String selector, Frame.HoverOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to hover over the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default String innerHTML(String selector)
element.innerHTML.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String innerHTML(String selector, Frame.InnerHTMLOptions options)
element.innerHTML.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default String innerText(String selector)
element.innerText.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String innerText(String selector, Frame.InnerTextOptions options)
element.innerText.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default boolean isChecked(String selector)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isChecked(String selector, Frame.IsCheckedOptions options)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isDetached()
true if the frame has been detached, or false otherwise.default boolean isDisabled(String selector)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isDisabled(String selector, Frame.IsDisabledOptions options)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default boolean isEditable(String selector)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isEditable(String selector, Frame.IsEditableOptions options)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default boolean isEnabled(String selector)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isEnabled(String selector, Frame.IsEnabledOptions options)
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default boolean isHidden(String selector)
selector that does not match any elements
is considered hidden.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isHidden(String selector, Frame.IsHiddenOptions options)
selector that does not match any elements
is considered hidden.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default boolean isVisible(String selector)
selector
that does not match any elements is considered not visible.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.boolean isVisible(String selector, Frame.IsVisibleOptions options)
selector
that does not match any elements is considered not visible.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String name()
If the name is empty, returns the id attribute instead.
NOTE: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
Page page()
Frame parentFrame()
null.default void press(String selector, String key)
key can specify the intended keyboardEvent.key value or a single
character to generate the text for. A superset of the key values can be found here. Examples of the keys are:
F1 - F12, Digit0- Digit9, KeyA- KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab,
Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, etc.
Following modification shortcuts are also supported: Shift, Control, Alt, Meta, ShiftLeft.
Holding down Shift will type the text that corresponds to the key in the upper case.
If key is a single character, it is case-sensitive, so the values a and A will generate different respective
texts.
Shortcuts such as key: "Control+o" or key: "Control+Shift+T" are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.key - Name of the key to press or a character to generate, such as ArrowLeft or a.void press(String selector, String key, Frame.PressOptions options)
key can specify the intended keyboardEvent.key value or a single
character to generate the text for. A superset of the key values can be found here. Examples of the keys are:
F1 - F12, Digit0- Digit9, KeyA- KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab,
Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, etc.
Following modification shortcuts are also supported: Shift, Control, Alt, Meta, ShiftLeft.
Holding down Shift will type the text that corresponds to the key in the upper case.
If key is a single character, it is case-sensitive, so the values a and A will generate different respective
texts.
Shortcuts such as key: "Control+o" or key: "Control+Shift+T" are supported as well. When specified with the
modifier, modifier is pressed and being held while the subsequent key is being pressed.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.key - Name of the key to press or a character to generate, such as ArrowLeft or a.ElementHandle querySelector(String selector)
The method finds an element matching the specified selector within the frame. See Working with selectors for more details. If no elements match the
selector, returns null.
selector - A selector to query for. See working with selectors for more
details.List<ElementHandle> querySelectorAll(String selector)
The method finds all elements matching the specified selector within the frame. See Working with selectors for more details. If no elements match the selector, returns empty array.
selector - A selector to query for. See working with selectors for more
details.default List<String> selectOption(String selector, String values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, String values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default List<String> selectOption(String selector, ElementHandle values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, ElementHandle values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default List<String> selectOption(String selector, String[] values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, String[] values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default List<String> selectOption(String selector, SelectOption values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, SelectOption values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default List<String> selectOption(String selector, ElementHandle[] values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, ElementHandle[] values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default List<String> selectOption(String selector, SelectOption[] values)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.List<String> selectOption(String selector, SelectOption[] values, Frame.SelectOptionOptions options)
selector, waits for actionability checks, waits until all specified options are
present in the <select> element and selects these options.
If the target element is not a <select> element, this method throws an error. However, if the element is inside the
<label> element that has an associated control, the control will be used
instead.
Returns the array of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
selector - A selector to query for. See working with selectors for more
details.values - Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the
first option matching one of the passed options is selected. String values are equivalent to {value:'string'}. Option
is considered matching if all specified properties match.default void setContent(String html)
html - HTML markup to assign to the page.void setContent(String html, Frame.SetContentOptions options)
html - HTML markup to assign to the page.default void setInputFiles(String selector, Path files)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void setInputFiles(String selector, Path files, Frame.SetInputFilesOptions options)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void setInputFiles(String selector, Path[] files)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void setInputFiles(String selector, Path[] files, Frame.SetInputFilesOptions options)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void setInputFiles(String selector, FilePayload files)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void setInputFiles(String selector, FilePayload files, Frame.SetInputFilesOptions options)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void setInputFiles(String selector, FilePayload[] files)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void setInputFiles(String selector, FilePayload[] files, Frame.SetInputFilesOptions options)
selector to point to an input element.
Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they
are resolved relative to the the current working directory. For empty array, clears the selected files.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default void tap(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.touchscreen() to tap the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
NOTE: frame.tap() requires that the hasTouch option of the browser context be set to true.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void tap(String selector, Frame.TapOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.touchscreen() to tap the center of the element, or the specified position.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
NOTE: frame.tap() requires that the hasTouch option of the browser context be set to true.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.default String textContent(String selector)
element.textContent.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String textContent(String selector, Frame.TextContentOptions options)
element.textContent.selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String title()
default void type(String selector, String text)
keydown, keypress/input, and keyup event for each character in the text. frame.type can be used to
send fine-grained keyboard events. To fill values in form fields, use Frame.fill().
To press a special key, like Control or ArrowDown, use Keyboard.press().
// Types instantly
frame.type("#mytextarea", "Hello");
// Types slower, like a user
frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.text - A text to type into a focused element.void type(String selector, String text, Frame.TypeOptions options)
keydown, keypress/input, and keyup event for each character in the text. frame.type can be used to
send fine-grained keyboard events. To fill values in form fields, use Frame.fill().
To press a special key, like Control or ArrowDown, use Keyboard.press().
// Types instantly
frame.type("#mytextarea", "Hello");
// Types slower, like a user
frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.text - A text to type into a focused element.default void uncheck(String selector)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.void uncheck(String selector, Frame.UncheckOptions options)
selector by performing the following steps:
selector. If there is none, wait until a matching element is attached to the DOM.force option is set. If the element is detached during the checks, the whole action is retried.Page.mouse() to click in the center of the element.noWaitAfter option is set. When all steps combined have not finished during the specified timeout, this method throws a TimeoutError. Passing
zero timeout disables this.
selector - A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See working with selectors for more details.String url()
default JSHandle waitForFunction(String expression, Object arg)
expression returns a truthy value, returns that value.
The Frame.waitForFunction() can be used to observe viewport size change:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType firefox = playwright.firefox();
Browser browser = firefox.launch();
Page page = browser.newPage();
page.setViewportSize(50, 50);
page.mainFrame().waitForFunction("window.innerWidth < 100");
browser.close();
}
}
}
To pass an argument to the predicate of frame.waitForFunction function:
String selector = ".foo";
frame.waitForFunction("selector => !!document.querySelector(selector)", selector);
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default JSHandle waitForFunction(String expression)
expression returns a truthy value, returns that value.
The Frame.waitForFunction() can be used to observe viewport size change:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType firefox = playwright.firefox();
Browser browser = firefox.launch();
Page page = browser.newPage();
page.setViewportSize(50, 50);
page.mainFrame().waitForFunction("window.innerWidth < 100");
browser.close();
}
}
}
To pass an argument to the predicate of frame.waitForFunction function:
String selector = ".foo";
frame.waitForFunction("selector => !!document.querySelector(selector)", selector);
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.JSHandle waitForFunction(String expression, Object arg, Frame.WaitForFunctionOptions options)
expression returns a truthy value, returns that value.
The Frame.waitForFunction() can be used to observe viewport size change:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType firefox = playwright.firefox();
Browser browser = firefox.launch();
Page page = browser.newPage();
page.setViewportSize(50, 50);
page.mainFrame().waitForFunction("window.innerWidth < 100");
browser.close();
}
}
}
To pass an argument to the predicate of frame.waitForFunction function:
String selector = ".foo";
frame.waitForFunction("selector => !!document.querySelector(selector)", selector);
expression - JavaScript expression to be evaluated in the browser context. If it looks like a function declaration, it is interpreted
as a function. Otherwise, evaluated as an expression.arg - Optional argument to pass to expression.default void waitForLoadState(LoadState state)
This returns when the frame reaches a required load state, load by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately.
frame.click("button"); // Click triggers navigation.
frame.waitForLoadState(); // Waits for "load" state by default.
state - Optional load state to wait for, defaults to load. If the state has been already reached while loading current
document, the method resolves immediately. Can be one of:
"load" - wait for the load event to be fired."domcontentloaded" - wait for the DOMContentLoaded event to be fired."networkidle" - wait until there are no network connections for at least 500 ms.default void waitForLoadState()
This returns when the frame reaches a required load state, load by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately.
frame.click("button"); // Click triggers navigation.
frame.waitForLoadState(); // Waits for "load" state by default.
void waitForLoadState(LoadState state, Frame.WaitForLoadStateOptions options)
This returns when the frame reaches a required load state, load by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately.
frame.click("button"); // Click triggers navigation.
frame.waitForLoadState(); // Waits for "load" state by default.
state - Optional load state to wait for, defaults to load. If the state has been already reached while loading current
document, the method resolves immediately. Can be one of:
"load" - wait for the load event to be fired."domcontentloaded" - wait for the DOMContentLoaded event to be fired."networkidle" - wait until there are no network connections for at least 500 ms.default Response waitForNavigation(Runnable callback)
null.
This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause the frame to navigate. Consider this example:
// The method returns after navigation has finished
Response response = frame.waitForNavigation(() -> {
// Clicking the link will indirectly cause a navigation
frame.click("a.delayed-navigation");
});
NOTE: Usage of the History API to change the URL is considered a navigation.
callback - Callback that performs the action triggering the event.Response waitForNavigation(Frame.WaitForNavigationOptions options, Runnable callback)
null.
This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause the frame to navigate. Consider this example:
// The method returns after navigation has finished
Response response = frame.waitForNavigation(() -> {
// Clicking the link will indirectly cause a navigation
frame.click("a.delayed-navigation");
});
NOTE: Usage of the History API to change the URL is considered a navigation.
callback - Callback that performs the action triggering the event.default ElementHandle waitForSelector(String selector)
state option. Returns null if waiting for hidden or
detached.
Wait for the selector to satisfy state option (either appear/disappear from dom, or become visible/hidden). If at
the moment of calling the method selector already satisfies the condition, the method will return immediately. If the
selector doesn't satisfy the condition for the timeout milliseconds, the function will throw.
This method works across navigations:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
Page page = browser.newPage();
for (String currentURL : Arrays.asList("https://google.com", "https://bbc.com")) {
page.navigate(currentURL);
ElementHandle element = page.mainFrame().waitForSelector("img");
System.out.println("Loaded image: " + element.getAttribute("src"));
}
browser.close();
}
}
}
selector - A selector to query for. See working with selectors for more
details.ElementHandle waitForSelector(String selector, Frame.WaitForSelectorOptions options)
state option. Returns null if waiting for hidden or
detached.
Wait for the selector to satisfy state option (either appear/disappear from dom, or become visible/hidden). If at
the moment of calling the method selector already satisfies the condition, the method will return immediately. If the
selector doesn't satisfy the condition for the timeout milliseconds, the function will throw.
This method works across navigations:
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
Page page = browser.newPage();
for (String currentURL : Arrays.asList("https://google.com", "https://bbc.com")) {
page.navigate(currentURL);
ElementHandle element = page.mainFrame().waitForSelector("img");
System.out.println("Loaded image: " + element.getAttribute("src"));
}
browser.close();
}
}
}
selector - A selector to query for. See working with selectors for more
details.void waitForTimeout(double timeout)
timeout in milliseconds.
Note that frame.waitForTimeout() should only be used for debugging. Tests using the timer in production are going to
be flaky. Use signals such as network events, selectors becoming visible and others instead.
timeout - A timeout to wait fordefault void waitForURL(String url)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.void waitForURL(String url, Frame.WaitForURLOptions options)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.default void waitForURL(Pattern url)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.void waitForURL(Pattern url, Frame.WaitForURLOptions options)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.default void waitForURL(Predicate<String> url)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.void waitForURL(Predicate<String> url, Frame.WaitForURLOptions options)
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
frame.waitForURL("**\/target.html");
url - A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.Copyright © 2021. All rights reserved.