Class FrameImpl
- All Implemented Interfaces:
Frame
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumprivate classprivate classNested classes/interfaces inherited from interface com.microsoft.playwright.Frame
Frame.AddScriptTagOptions, Frame.AddStyleTagOptions, Frame.CheckOptions, Frame.ClickOptions, Frame.DblclickOptions, Frame.DispatchEventOptions, Frame.DragAndDropOptions, Frame.EvalOnSelectorOptions, Frame.FillOptions, Frame.FocusOptions, Frame.GetAttributeOptions, Frame.GetByAltTextOptions, Frame.GetByLabelOptions, Frame.GetByPlaceholderOptions, Frame.GetByRoleOptions, Frame.GetByTextOptions, Frame.GetByTitleOptions, Frame.HoverOptions, Frame.InnerHTMLOptions, Frame.InnerTextOptions, Frame.InputValueOptions, Frame.IsCheckedOptions, Frame.IsDisabledOptions, Frame.IsEditableOptions, Frame.IsEnabledOptions, Frame.IsHiddenOptions, Frame.IsVisibleOptions, Frame.LocatorOptions, Frame.NavigateOptions, Frame.PressOptions, Frame.QuerySelectorOptions, Frame.SelectOptionOptions, Frame.SetCheckedOptions, Frame.SetContentOptions, Frame.SetInputFilesOptions, Frame.TapOptions, Frame.TextContentOptions, Frame.TypeOptions, Frame.UncheckOptions, Frame.WaitForFunctionOptions, Frame.WaitForLoadStateOptions, Frame.WaitForNavigationOptions, Frame.WaitForSelectorOptions, Frame.WaitForURLOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ListenerCollection<FrameImpl.InternalEventType> (package private) booleanprivate final Set<WaitUntilState> private String(package private) PageImpl(package private) FrameImplprivate StringFields inherited from class com.microsoft.playwright.impl.ChannelOwner
connection, guid, initializer, type -
Constructor Summary
ConstructorsConstructorDescriptionFrameImpl(ChannelOwner parent, String type, String guid, com.google.gson.JsonObject initializer) -
Method Summary
Modifier and TypeMethodDescriptionaddScriptTag(Frame.AddScriptTagOptions options) Returns the added tag when the script's onload fires or when the script content was injected into frame.(package private) ElementHandleaddStyleTag(Frame.AddStyleTagOptions options) Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.(package private) ElementHandleaddStyleTagImpl(Frame.AddStyleTagOptions options) voidcheck(String selector, Frame.CheckOptions options) This method checks an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voidcheckImpl(String selector, Frame.CheckOptions options) voidclick(String selector, Frame.ClickOptions options) This method clicks an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voidclickImpl(String selector, Frame.ClickOptions options) content()Gets the full HTML contents of the frame, including the doctype.(package private) Stringvoiddblclick(String selector, Frame.DblclickOptions options) This method double clicks an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voiddblclickImpl(String selector, Frame.DblclickOptions options) voiddispatchEvent(String selector, String type, Object eventInit, Frame.DispatchEventOptions options) The snippet below dispatches theclickevent on the element.(package private) voiddispatchEventImpl(String selector, String type, Object eventInit, Frame.DispatchEventOptions options) voiddragAndDrop(String source, String target, Frame.DragAndDropOptions options) (package private) voiddragAndDropImpl(String source, String target, Frame.DragAndDropOptions options) evalOnSelector(String selector, String pageFunction, Object arg, Frame.EvalOnSelectorOptions options) Returns the return value ofexpression.evalOnSelectorAll(String selector, String pageFunction, Object arg) Returns the return value ofexpression.(package private) ObjectevalOnSelectorAllImpl(String selector, String pageFunction, Object arg) (package private) ObjectevalOnSelectorImpl(String selector, String pageFunction, Object arg, Frame.EvalOnSelectorOptions options) Returns the return value ofexpression.evaluateHandle(String pageFunction, Object arg) Returns the return value ofexpressionas aJSHandle.(package private) JSHandleevaluateHandleImpl(String pageFunction, Object arg) (package private) ObjectevaluateImpl(String expression, Object arg) voidfill(String selector, String value, Frame.FillOptions options) This method waits for an element matchingselector, waits for actionability checks, focuses the element, fills it and triggers aninputevent after filling.(package private) voidfillImpl(String selector, String value, Frame.FillOptions options) voidfocus(String selector, Frame.FocusOptions options) This method fetches an element withselectorand focuses it.(package private) voidfocusImpl(String selector, Frame.FocusOptions options) Returns theframeoriframeelement handle which corresponds to this frame.(package private) ElementHandleframeLocator(String selector) When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.getAttribute(String selector, String name, Frame.GetAttributeOptions options) Returns element attribute value.(package private) StringgetAttributeImpl(String selector, String name, Frame.GetAttributeOptions options) getByAltText(String text, Frame.GetByAltTextOptions options) Allows locating elements by their alt text.getByAltText(Pattern text, Frame.GetByAltTextOptions options) Allows locating elements by their alt text.getByLabel(String text, Frame.GetByLabelOptions options) Allows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.getByLabel(Pattern text, Frame.GetByLabelOptions options) Allows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.getByPlaceholder(String text, Frame.GetByPlaceholderOptions options) Allows locating input elements by the placeholder text.getByPlaceholder(Pattern text, Frame.GetByPlaceholderOptions options) Allows locating input elements by the placeholder text.getByRole(AriaRole role, Frame.GetByRoleOptions options) getByTestId(String testId) Locate element by the test id.getByTestId(Pattern testId) Locate element by the test id.getByText(String text, Frame.GetByTextOptions options) Allows locating elements that contain given text.getByText(Pattern text, Frame.GetByTextOptions options) Allows locating elements that contain given text.getByTitle(String text, Frame.GetByTitleOptions options) Allows locating elements by their title attribute.getByTitle(Pattern text, Frame.GetByTitleOptions options) Allows locating elements by their title attribute.protected voidhandleEvent(String event, com.google.gson.JsonObject params) (package private) voidhighlightImpl(String selector) voidhover(String selector, Frame.HoverOptions options) This method hovers over an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voidhoverImpl(String selector, Frame.HoverOptions options) innerHTML(String selector, Frame.InnerHTMLOptions options) Returnselement.innerHTML.(package private) StringinnerHTMLImpl(String selector, Frame.InnerHTMLOptions options) innerText(String selector, Frame.InnerTextOptions options) Returnselement.innerText.(package private) StringinnerTextImpl(String selector, Frame.InnerTextOptions options) inputValue(String selector, Frame.InputValueOptions options) Returnsinput.valuefor the selected<input>or<textarea>or<select>element.(package private) StringinputValueImpl(String selector, Frame.InputValueOptions options) booleanisChecked(String selector, Frame.IsCheckedOptions options) Returns whether the element is checked.(package private) booleanisCheckedImpl(String selector, Frame.IsCheckedOptions options) booleanReturnstrueif the frame has been detached, orfalseotherwise.booleanisDisabled(String selector, Frame.IsDisabledOptions options) Returns whether the element is disabled, the opposite of enabled.(package private) booleanisDisabledImpl(String selector, Frame.IsDisabledOptions options) booleanisEditable(String selector, Frame.IsEditableOptions options) Returns whether the element is editable.(package private) booleanisEditableImpl(String selector, Frame.IsEditableOptions options) booleanisEnabled(String selector, Frame.IsEnabledOptions options) Returns whether the element is enabled.(package private) booleanisEnabledImpl(String selector, Frame.IsEnabledOptions options) booleanisHidden(String selector, Frame.IsHiddenOptions options) Returns whether the element is hidden, the opposite of visible.(package private) booleanisHiddenImpl(String selector, Frame.IsHiddenOptions options) booleanisVisible(String selector, Frame.IsVisibleOptions options) Returns whether the element is visible.(package private) booleanisVisibleImpl(String selector, Frame.IsVisibleOptions options) private static WaitUntilStateloadStateFromProtocol(String value) locator(String selector, Frame.LocatorOptions options) The method returns an element locator that can be used to perform actions on this page / frame.name()Returns frame's name attribute as specified in the tag.navigate(String url, Frame.NavigateOptions options) Returns the main resource response.(package private) ResponseImplnavigateImpl(String url, Frame.NavigateOptions options) page()Returns the page containing this frame.Parent frame, if any.voidpress(String selector, String key, Frame.PressOptions options) keycan specify the intended keyboardEvent.key value or a single character to generate the text for.(package private) voidpressImpl(String selector, String key, Frame.PressOptions options) (package private) intqueryCount(String selector) querySelector(String selector, Frame.QuerySelectorOptions options) Returns the ElementHandle pointing to the frame element.querySelectorAll(String selector) Returns the ElementHandles pointing to the frame elements.(package private) List<ElementHandle> querySelectorAllImpl(String selector) (package private) ElementHandleImplquerySelectorImpl(String selector, Frame.QuerySelectorOptions options) selectOption(com.google.gson.JsonObject params) selectOption(String selector, ElementHandle[] values, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOption(String selector, ElementHandle value, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOption(String selector, SelectOption[] values, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOption(String selector, SelectOption value, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOption(String selector, String[] values, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOption(String selector, String value, Frame.SelectOptionOptions options) This method waits for an element matchingselector, waits for actionability checks, waits until all specified options are present in the<select>element and selects these options.selectOptionImpl(String selector, ElementHandle[] values, Frame.SelectOptionOptions options) selectOptionImpl(String selector, SelectOption[] values, Frame.SelectOptionOptions options) selectOptionImpl(String selector, String[] values, Frame.SelectOptionOptions options) voidsetChecked(String selector, boolean checked, Frame.SetCheckedOptions options) This method checks or unchecks an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voidsetCheckedImpl(String selector, boolean checked, Frame.SetCheckedOptions options) voidsetContent(String html, Frame.SetContentOptions options) This method internally calls document.write(), inheriting all its specific characteristics and behaviors.(package private) voidsetContentImpl(String html, Frame.SetContentOptions options) voidsetInputFiles(String selector, FilePayload[] files, Frame.SetInputFilesOptions options) Sets the value of the file input to these file paths or files.voidsetInputFiles(String selector, FilePayload files, Frame.SetInputFilesOptions options) Sets the value of the file input to these file paths or files.voidsetInputFiles(String selector, Path[] files, Frame.SetInputFilesOptions options) Sets the value of the file input to these file paths or files.voidsetInputFiles(String selector, Path files, Frame.SetInputFilesOptions options) Sets the value of the file input to these file paths or files.(package private) voidsetInputFilesImpl(String selector, FilePayload[] files, Frame.SetInputFilesOptions options) (package private) voidsetInputFilesImpl(String selector, Path[] files, Frame.SetInputFilesOptions options) voidtap(String selector, Frame.TapOptions options) This method taps an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voidtapImpl(String selector, Frame.TapOptions options) textContent(String selector, Frame.TextContentOptions options) Returnselement.textContent.(package private) StringtextContentImpl(String selector, Frame.TextContentOptions options) title()Returns the page title.(package private) Stringvoidtype(String selector, String text, Frame.TypeOptions options) (package private) voidtypeImpl(String selector, String text, Frame.TypeOptions options) voiduncheck(String selector, Frame.UncheckOptions options) This method checks an element matchingselectorby performing the following steps: Find an element matchingselector.(package private) voiduncheckImpl(String selector, Frame.UncheckOptions options) url()Returns frame's url.waitForFunction(String pageFunction, Object arg, Frame.WaitForFunctionOptions options) Returns when theexpressionreturns a truthy value, returns that value.(package private) JSHandlewaitForFunctionImpl(String pageFunction, Object arg, Frame.WaitForFunctionOptions options) voidwaitForLoadState(LoadState state, Frame.WaitForLoadStateOptions options) Waits for the required load state to be reached.(package private) voidwaitForLoadStateImpl(LoadState state, Frame.WaitForLoadStateOptions options, Logger logger) private voidwaitForLoadStateImpl(WaitUntilState state, Frame.WaitForLoadStateOptions options, Logger logger) waitForNavigation(Frame.WaitForNavigationOptions options, Runnable code) (package private) ResponsewaitForNavigationImpl(Logger logger, Runnable code, Frame.WaitForNavigationOptions options) private ResponsewaitForNavigationImpl(Logger logger, Runnable code, Frame.WaitForNavigationOptions options, UrlMatcher matcher) waitForSelector(String selector, Frame.WaitForSelectorOptions options) Returns when element specified by selector satisfiesstateoption.(package private) ElementHandlewaitForSelectorImpl(String selector, Frame.WaitForSelectorOptions options) (package private) ElementHandlewaitForSelectorImpl(String selector, Frame.WaitForSelectorOptions options, boolean omitReturnValue) voidwaitForTimeout(double timeout) Waits for the giventimeoutin milliseconds.(package private) voidwaitForTimeoutImpl(double timeout) private voidwaitForURL(UrlMatcher matcher, Frame.WaitForURLOptions options) voidwaitForURL(String url, Frame.WaitForURLOptions options) Waits for the frame to navigate to the given URL.voidwaitForURL(Predicate<String> url, Frame.WaitForURLOptions options) Waits for the frame to navigate to the given URL.voidwaitForURL(Pattern url, Frame.WaitForURLOptions options) Waits for the frame to navigate to the given URL.(package private) voidwaitForURLImpl(Logger logger, UrlMatcher matcher, Frame.WaitForURLOptions options) Methods inherited from class com.microsoft.playwright.impl.ChannelOwner
adopt, disposeChannelOwner, runUntil, sendMessage, sendMessage, sendMessageAsync, toProtocolRef, withLogging, withWaitLoggingMethods inherited from class com.microsoft.playwright.impl.LoggingSupport
logApi, logApiIfEnabled, logWithTimestamp, withLoggingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.microsoft.playwright.Frame
addScriptTag, addStyleTag, check, click, dblclick, dispatchEvent, dispatchEvent, dragAndDrop, evalOnSelector, evalOnSelector, evalOnSelectorAll, evaluate, evaluateHandle, fill, focus, getAttribute, getByAltText, getByAltText, getByLabel, getByLabel, getByPlaceholder, getByPlaceholder, getByRole, getByText, getByText, getByTitle, getByTitle, hover, innerHTML, innerText, inputValue, isChecked, isDisabled, isEditable, isEnabled, isHidden, isVisible, locator, navigate, press, querySelector, selectOption, selectOption, selectOption, selectOption, selectOption, selectOption, setChecked, setContent, setInputFiles, setInputFiles, setInputFiles, setInputFiles, tap, textContent, type, uncheck, waitForFunction, waitForFunction, waitForLoadState, waitForLoadState, waitForNavigation, waitForSelector, waitForURL, waitForURL, waitForURL
-
Field Details
-
Constructor Details
-
FrameImpl
FrameImpl(ChannelOwner parent, String type, String guid, com.google.gson.JsonObject initializer)
-
-
Method Details
-
loadStateFromProtocol
-
querySelector
Description copied from interface:FrameReturns the ElementHandle pointing to the frame element.NOTE: The use of
ElementHandleis discouraged, useLocatorobjects and web-first assertions instead.The method finds an element matching the specified selector within the frame. If no elements match the selector, returns
null.- Specified by:
querySelectorin interfaceFrame- Parameters:
selector- A selector to query for.
-
querySelectorImpl
-
querySelectorAll
Description copied from interface:FrameReturns the ElementHandles pointing to the frame elements.NOTE: The use of
ElementHandleis discouraged, useLocatorobjects instead.The method finds all elements matching the specified selector within the frame. If no elements match the selector, returns empty array.
- Specified by:
querySelectorAllin interfaceFrame- Parameters:
selector- A selector to query for.
-
selectOption
Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.value- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
selectOption
public List<String> selectOption(String selector, ElementHandle value, Frame.SelectOptionOptions options) Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.value- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
selectOption
public List<String> selectOption(String selector, String[] values, Frame.SelectOptionOptions options) Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.values- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
selectOption
public List<String> selectOption(String selector, SelectOption value, Frame.SelectOptionOptions options) Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.value- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
querySelectorAllImpl
-
evalOnSelector
public Object evalOnSelector(String selector, String pageFunction, Object arg, Frame.EvalOnSelectorOptions options) Description copied from interface:FrameReturns the return value ofexpression.The method finds an element matching the specified selector within the frame and passes it as a first argument to
expression. If no elements match the selector, the method throws an error.If
expressionreturns a Promise, thenFrame.evalOnSelector()would wait for the promise to resolve and return its value.**Usage**
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");- Specified by:
evalOnSelectorin interfaceFrame- Parameters:
selector- A selector to query for.pageFunction- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.
-
evalOnSelectorImpl
Object evalOnSelectorImpl(String selector, String pageFunction, Object arg, Frame.EvalOnSelectorOptions options) -
evalOnSelectorAll
Description copied from interface:FrameReturns the return value ofexpression.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.If
expressionreturns a Promise, thenFrame.evalOnSelectorAll()would wait for the promise to resolve and return its value.**Usage**
boolean divsCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);- Specified by:
evalOnSelectorAllin interfaceFrame- Parameters:
selector- A selector to query for.pageFunction- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.
-
evalOnSelectorAllImpl
-
addScriptTag
Description copied from interface:FrameReturns the added tag when the script's onload fires or when the script content was injected into frame.Adds a
<script>tag into the page with the desired url or content.- Specified by:
addScriptTagin interfaceFrame
-
addScriptTagImpl
-
addStyleTag
Description copied from interface:FrameReturns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.Adds a
<link rel="stylesheet">tag into the page with the desired url or a<style type="text/css">tag with the content.- Specified by:
addStyleTagin interfaceFrame
-
addStyleTagImpl
-
check
Description copied from interface:FrameThis method checks an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
- Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to click in the center of the element. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set. - Ensure that the element is now checked. If not, this method throws.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this. - Find an element matching
-
checkImpl
-
childFrames
- Specified by:
childFramesin interfaceFrame
-
click
Description copied from interface:FrameThis method clicks an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to click in the center of the element, or the specifiedposition. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this. - Find an element matching
-
clickImpl
-
content
Description copied from interface:FrameGets the full HTML contents of the frame, including the doctype. -
contentImpl
String contentImpl() -
dblclick
Description copied from interface:FrameThis method double clicks an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to double click in the center of the element, or the specifiedposition. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set. Note that if the first click of thedblclick()triggers a navigation event, this method will throw.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this.NOTE:
frame.dblclick()dispatches twoclickevents and a singledblclickevent. - Find an element matching
-
dblclickImpl
-
dispatchEvent
public void dispatchEvent(String selector, String type, Object eventInit, Frame.DispatchEventOptions options) Description copied from interface:FrameThe snippet below dispatches theclickevent on the element. Regardless of the visibility state of the element,clickis dispatched. This is equivalent to calling element.click().**Usage**
frame.dispatchEvent("button#submit", "click");Under the hood, it creates an instance of an event based on the given
type, initializes it witheventInitproperties and dispatches it on the element. Events arecomposed,cancelableand bubble by default.Since
eventInitis event-specific, please refer to the events documentation for the lists of initial properties:You can also specify
JSHandleas 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);- Specified by:
dispatchEventin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.type- DOM event type:"click","dragstart", etc.eventInit- Optional event-specific initialization properties.
-
dispatchEventImpl
void dispatchEventImpl(String selector, String type, Object eventInit, Frame.DispatchEventOptions options) -
evaluate
Description copied from interface:FrameReturns the return value ofexpression.If the function passed to the
Frame.evaluate()returns a Promise, thenFrame.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, thenFrame.evaluate()returnsundefined. Playwright also supports transferring some additional values that are not serializable byJSON:-0,NaN,Infinity,-Infinity.**Usage**
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"ElementHandleinstances can be passed as an argument to theFrame.evaluate():ElementHandle bodyHandle = frame.evaluate("document.body"); String html = (String) frame.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello")); bodyHandle.dispose(); -
evaluateImpl
-
evaluateHandle
Description copied from interface:FrameReturns the return value ofexpressionas aJSHandle.The only difference between
Frame.evaluate()andFrame.evaluateHandle()is thatFrame.evaluateHandle()returnsJSHandle.If the function, passed to the
Frame.evaluateHandle(), returns a Promise, thenFrame.evaluateHandle()would wait for the promise to resolve and return its value.**Usage**
// 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".JSHandleinstances can be passed as an argument to theFrame.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();- Specified by:
evaluateHandlein interfaceFrame- Parameters:
pageFunction- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.
-
evaluateHandleImpl
-
fill
Description copied from interface:FrameThis method waits for an element matchingselector, waits for actionability checks, focuses the element, fills it and triggers aninputevent 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
Locator.pressSequentially(). -
fillImpl
-
focus
Description copied from interface:FrameThis method fetches an element withselectorand focuses it. If there's no element matchingselector, the method waits until a matching element appears in the DOM. -
focusImpl
-
frameElement
Description copied from interface:FrameReturns theframeoriframeelement 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.**Usage**
ElementHandle frameElement = frame.frameElement(); Frame contentFrame = frameElement.contentFrame(); System.out.println(frame == contentFrame); // -> true- Specified by:
frameElementin interfaceFrame
-
frameLocator
Description copied from interface:FrameWhen working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.**Usage**
Following snippet locates element with text "Submit" in the iframe with id
my-frame, like<iframe id="my-frame">:Locator locator = frame.frameLocator("#my-iframe").getByText("Submit"); locator.click();- Specified by:
frameLocatorin interfaceFrame- Parameters:
selector- A selector to use when resolving DOM element.
-
frameElementImpl
ElementHandle frameElementImpl() -
getAttribute
Description copied from interface:FrameReturns element attribute value.- Specified by:
getAttributein interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.name- Attribute name to get the value for.
-
getByAltText
Description copied from interface:FrameAllows locating elements by their alt text.**Usage**
For example, this method will find the image by alt text "Playwright logo":
page.getByAltText("Playwright logo").click();- Specified by:
getByAltTextin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByAltText
Description copied from interface:FrameAllows locating elements by their alt text.**Usage**
For example, this method will find the image by alt text "Playwright logo":
page.getByAltText("Playwright logo").click();- Specified by:
getByAltTextin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByLabel
Description copied from interface:FrameAllows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.**Usage**
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
page.getByLabel("Username").fill("john"); page.getByLabel("Password").fill("secret");- Specified by:
getByLabelin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByLabel
Description copied from interface:FrameAllows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.**Usage**
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
page.getByLabel("Username").fill("john"); page.getByLabel("Password").fill("secret");- Specified by:
getByLabelin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByPlaceholder
Description copied from interface:FrameAllows locating input elements by the placeholder text.**Usage**
For example, consider the following DOM structure.
You can fill the input after locating it by the placeholder text:
page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");- Specified by:
getByPlaceholderin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByPlaceholder
Description copied from interface:FrameAllows locating input elements by the placeholder text.**Usage**
For example, consider the following DOM structure.
You can fill the input after locating it by the placeholder text:
page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");- Specified by:
getByPlaceholderin interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByRole
Description copied from interface:FrameAllows locating elements by their ARIA role, ARIA attributes and accessible name.**Usage**
Consider the following DOM structure.
You can locate each element by it's implicit role:
assertThat(page .getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Sign up"))) .isVisible(); page.getByRole(AriaRole.CHECKBOX, new Page.GetByRoleOptions().setName("Subscribe")) .check(); page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName( Pattern.compile("submit", Pattern.CASE_INSENSITIVE))) .click();**Details**
Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
Many html elements have an implicitly defined role that is recognized by the role selector. You can find all the supported roles here. ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting
roleand/oraria-*attributes to default values. -
getByTestId
Description copied from interface:FrameLocate element by the test id.**Usage**
Consider the following DOM structure.
You can locate the element by it's test id:
page.getByTestId("directions").click();**Details**
By default, the
data-testidattribute is used as a test id. UseSelectors.setTestIdAttribute()to configure a different test id attribute if necessary.- Specified by:
getByTestIdin interfaceFrame- Parameters:
testId- Id to locate the element by.
-
getByTestId
Description copied from interface:FrameLocate element by the test id.**Usage**
Consider the following DOM structure.
You can locate the element by it's test id:
page.getByTestId("directions").click();**Details**
By default, the
data-testidattribute is used as a test id. UseSelectors.setTestIdAttribute()to configure a different test id attribute if necessary.- Specified by:
getByTestIdin interfaceFrame- Parameters:
testId- Id to locate the element by.
-
getByText
Description copied from interface:FrameAllows locating elements that contain given text.See also
Locator.filter()that allows to match by another criteria, like an accessible role, and then filter by the text content.**Usage**
Consider the following DOM structure:
You can locate by text substring, exact string, or a regular expression:
// Matches <span> page.getByText("world") // Matches first <div> page.getByText("Hello world") // Matches second <div> page.getByText("Hello", new Page.GetByTextOptions().setExact(true)) // Matches both <div>s page.getByText(Pattern.compile("Hello")) // Matches second <div> page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type
buttonandsubmitare matched by theirvalueinstead of the text content. For example, locating by text"Log in"matches<input type=button value="Log in">. -
getByText
Description copied from interface:FrameAllows locating elements that contain given text.See also
Locator.filter()that allows to match by another criteria, like an accessible role, and then filter by the text content.**Usage**
Consider the following DOM structure:
You can locate by text substring, exact string, or a regular expression:
// Matches <span> page.getByText("world") // Matches first <div> page.getByText("Hello world") // Matches second <div> page.getByText("Hello", new Page.GetByTextOptions().setExact(true)) // Matches both <div>s page.getByText(Pattern.compile("Hello")) // Matches second <div> page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type
buttonandsubmitare matched by theirvalueinstead of the text content. For example, locating by text"Log in"matches<input type=button value="Log in">. -
getByTitle
Description copied from interface:FrameAllows locating elements by their title attribute.**Usage**
Consider the following DOM structure.
You can check the issues count after locating it by the title text:
assertThat(page.getByTitle("Issues count")).hasText("25 issues");- Specified by:
getByTitlein interfaceFrame- Parameters:
text- Text to locate the element for.
-
getByTitle
Description copied from interface:FrameAllows locating elements by their title attribute.**Usage**
Consider the following DOM structure.
You can check the issues count after locating it by the title text:
assertThat(page.getByTitle("Issues count")).hasText("25 issues");- Specified by:
getByTitlein interfaceFrame- Parameters:
text- Text to locate the element for.
-
getAttributeImpl
-
hover
Description copied from interface:FrameThis method hovers over an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to hover over the center of the element, or the specifiedposition. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this. - Find an element matching
-
hoverImpl
-
dragAndDrop
- Specified by:
dragAndDropin interfaceFrame- Parameters:
source- A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be used.target- A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will be used.
-
dragAndDropImpl
-
innerHTML
Description copied from interface:FrameReturnselement.innerHTML. -
innerHTMLImpl
-
innerText
Description copied from interface:FrameReturnselement.innerText. -
innerTextImpl
-
inputValue
Description copied from interface:FrameReturnsinput.valuefor the selected<input>or<textarea>or<select>element.Throws for non-input elements. However, if the element is inside the
<label>element that has an associated control, returns the value of the control.- Specified by:
inputValuein interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
inputValueImpl
-
isChecked
Description copied from interface:FrameReturns whether the element is checked. Throws if the element is not a checkbox or radio input. -
isCheckedImpl
-
isDetached
public boolean isDetached()Description copied from interface:FrameReturnstrueif the frame has been detached, orfalseotherwise.- Specified by:
isDetachedin interfaceFrame
-
isDisabled
Description copied from interface:FrameReturns whether the element is disabled, the opposite of enabled.- Specified by:
isDisabledin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
isDisabledImpl
-
isEditable
Description copied from interface:FrameReturns whether the element is editable.- Specified by:
isEditablein interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
isEditableImpl
-
isEnabled
Description copied from interface:FrameReturns whether the element is enabled. -
isEnabledImpl
-
isHidden
Description copied from interface:FrameReturns whether the element is hidden, the opposite of visible.selectorthat does not match any elements is considered hidden. -
isHiddenImpl
-
isVisible
Description copied from interface:FrameReturns whether the element is visible.selectorthat does not match any elements is considered not visible. -
locator
Description copied from interface:FrameThe method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed. -
isVisibleImpl
-
name
Description copied from interface:FrameReturns frame's name attribute as specified in the tag.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
Description copied from interface:FrameReturns the page containing this frame. -
parentFrame
Description copied from interface:FrameParent frame, if any. Detached frames and main frames returnnull.- Specified by:
parentFramein interfaceFrame
-
press
Description copied from interface:Framekeycan specify the intended keyboardEvent.key value or a single character to generate the text for. A superset of thekeyvalues 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
Shiftwill type the text that corresponds to thekeyin the upper case.If
keyis a single character, it is case-sensitive, so the valuesaandAwill generate different respective texts.Shortcuts such as
key: "Control+o"orkey: "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. -
pressImpl
-
selectOption
public List<String> selectOption(String selector, SelectOption[] values, Frame.SelectOptionOptions options) Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.values- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
selectOptionImpl
List<String> selectOptionImpl(String selector, SelectOption[] values, Frame.SelectOptionOptions options) -
selectOptionImpl
-
selectOption
public List<String> selectOption(String selector, ElementHandle[] values, Frame.SelectOptionOptions options) Description copied from interface:FrameThis method waits for an element matchingselector, 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
changeandinputevent once all the provided options have been selected.**Usage**
// Single selection matching the value or label 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"});- Specified by:
selectOptionin interfaceFrame- Parameters:
selector- A selector to query for.values- Options to select. If the<select>has themultipleattribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.
-
selectOptionImpl
List<String> selectOptionImpl(String selector, ElementHandle[] values, Frame.SelectOptionOptions options) -
selectOption
-
setChecked
Description copied from interface:FrameThis method checks or unchecks an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method throws.
- If the element already has the right checked state, this method returns immediately.
- Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to click in the center of the element. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set. - Ensure that the element is now checked or unchecked. If not, this method throws.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this.- Specified by:
setCheckedin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.checked- Whether to check or uncheck the checkbox.
- Find an element matching
-
setCheckedImpl
-
setContent
Description copied from interface:FrameThis method internally calls document.write(), inheriting all its specific characteristics and behaviors.- Specified by:
setContentin interfaceFrame- Parameters:
html- HTML markup to assign to the page.
-
setInputFiles
Description copied from interface:FrameSets the value of the file input to these file paths or files. If some of thefilePathsare relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.This method expects
selectorto point to an input element. However, if the element is inside the<label>element that has an associated control, targets the control instead.- Specified by:
setInputFilesin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
setContentImpl
-
setInputFiles
Description copied from interface:FrameSets the value of the file input to these file paths or files. If some of thefilePathsare relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.This method expects
selectorto point to an input element. However, if the element is inside the<label>element that has an associated control, targets the control instead.- Specified by:
setInputFilesin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
setInputFilesImpl
-
setInputFiles
Description copied from interface:FrameSets the value of the file input to these file paths or files. If some of thefilePathsare relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.This method expects
selectorto point to an input element. However, if the element is inside the<label>element that has an associated control, targets the control instead.- Specified by:
setInputFilesin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
setInputFiles
Description copied from interface:FrameSets the value of the file input to these file paths or files. If some of thefilePathsare relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.This method expects
selectorto point to an input element. However, if the element is inside the<label>element that has an associated control, targets the control instead.- Specified by:
setInputFilesin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
setInputFilesImpl
-
tap
Description copied from interface:FrameThis method taps an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.touchscreen()to tap the center of the element, or the specifiedposition. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this.NOTE:
frame.tap()requires that thehasTouchoption of the browser context be set to true. - Find an element matching
-
tapImpl
-
textContent
Description copied from interface:FrameReturnselement.textContent.- Specified by:
textContentin interfaceFrame- Parameters:
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
-
textContentImpl
-
title
Description copied from interface:FrameReturns the page title. -
titleImpl
String titleImpl() -
type
-
typeImpl
-
uncheck
Description copied from interface:FrameThis method checks an element matchingselectorby performing the following steps:- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already unchecked, this method returns immediately.
- Wait for actionability checks on the matched element,
unless
forceoption is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.mouse()to click in the center of the element. - Wait for initiated navigations to either succeed or fail, unless
noWaitAfteroption is set. - Ensure that the element is now unchecked. If not, this method throws.
When all steps combined have not finished during the specified
timeout, this method throws aTimeoutError. Passing zero timeout disables this. - Find an element matching
-
uncheckImpl
-
url
Description copied from interface:FrameReturns frame's url. -
waitForFunction
public JSHandle waitForFunction(String pageFunction, Object arg, Frame.WaitForFunctionOptions options) Description copied from interface:FrameReturns when theexpressionreturns a truthy value, returns that value.**Usage**
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.waitForFunctionfunction:String selector = ".foo"; frame.waitForFunction("selector => !!document.querySelector(selector)", selector);- Specified by:
waitForFunctionin interfaceFrame- Parameters:
pageFunction- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.arg- Optional argument to pass toexpression.
-
waitForFunctionImpl
-
waitForLoadState
Description copied from interface:FrameWaits for the required load state to be reached.This returns when the frame reaches a required load state,
loadby default. The navigation must have been committed when this method is called. If current document has already reached the required state, resolves immediately.**Usage**
frame.click("button"); // Click triggers navigation. frame.waitForLoadState(); // Waits for "load" state by default.- Specified by:
waitForLoadStatein interfaceFrame- Parameters:
state- Optional load state to wait for, defaults toload. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:-
"load"- wait for theloadevent to be fired. -
"domcontentloaded"- wait for theDOMContentLoadedevent to be fired. -
"networkidle"- **DISCOURAGED** wait until there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
-
-
waitForLoadStateImpl
-
waitForLoadStateImpl
private void waitForLoadStateImpl(WaitUntilState state, Frame.WaitForLoadStateOptions options, Logger logger) -
waitForSelector
Description copied from interface:FrameReturns when element specified by selector satisfiesstateoption. Returnsnullif waiting forhiddenordetached.NOTE: Playwright automatically waits for element to be ready before performing an action. Using
Locatorobjects and web-first assertions make the code wait-for-selector-free.Wait for the
selectorto satisfystateoption (either appear/disappear from dom, or become visible/hidden). If at the moment of calling the methodselectoralready satisfies the condition, the method will return immediately. If the selector doesn't satisfy the condition for thetimeoutmilliseconds, the function will throw.**Usage**
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(); } } }- Specified by:
waitForSelectorin interfaceFrame- Parameters:
selector- A selector to query for.
-
waitForSelectorImpl
-
waitForSelectorImpl
ElementHandle waitForSelectorImpl(String selector, Frame.WaitForSelectorOptions options, boolean omitReturnValue) -
waitForTimeout
public void waitForTimeout(double timeout) Description copied from interface:FrameWaits for the giventimeoutin 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.- Specified by:
waitForTimeoutin interfaceFrame- Parameters:
timeout- A timeout to wait for
-
waitForTimeoutImpl
void waitForTimeoutImpl(double timeout) -
waitForURL
Description copied from interface:FrameWaits for the frame to navigate to the given URL.**Usage**
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation frame.waitForURL("**\/target.html");- Specified by:
waitForURLin interfaceFrame- Parameters:
url- A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
-
waitForURL
Description copied from interface:FrameWaits for the frame to navigate to the given URL.**Usage**
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation frame.waitForURL("**\/target.html");- Specified by:
waitForURLin interfaceFrame- Parameters:
url- A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
-
waitForURL
Description copied from interface:FrameWaits for the frame to navigate to the given URL.**Usage**
frame.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation frame.waitForURL("**\/target.html");- Specified by:
waitForURLin interfaceFrame- Parameters:
url- A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
-
waitForURL
-
waitForURLImpl
-
queryCount
-
highlightImpl
-
handleEvent
- Overrides:
handleEventin classChannelOwner
-