public interface Locator
Page.locator()
method.
Modifier and Type | Method and Description |
---|---|
List<String> |
allInnerTexts()
Returns an array of
node.innerText values for all matching nodes. |
List<String> |
allTextContents()
Returns an array of
node.textContent values for all matching nodes. |
default void |
blur()
Calls blur on the element.
|
void |
blur(Locator.BlurOptions options)
Calls blur on the element.
|
default BoundingBox |
boundingBox()
This method returns the bounding box of the element, or
null if the element is not visible. |
BoundingBox |
boundingBox(Locator.BoundingBoxOptions options)
This method returns the bounding box of the element, or
null if the element is not visible. |
default void |
check()
This method checks the element by performing the following steps:
Ensure that element is a checkbox or a radio input.
|
void |
check(Locator.CheckOptions options)
This method checks the element by performing the following steps:
Ensure that element is a checkbox or a radio input.
|
default void |
clear()
This method waits for actionability checks, focuses the
element, clears it and triggers an
input event after clearing. |
void |
clear(Locator.ClearOptions options)
This method waits for actionability checks, focuses the
element, clears it and triggers an
input event after clearing. |
default void |
click()
This method clicks the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to click in the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
void |
click(Locator.ClickOptions options)
This method clicks the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to click in the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
int |
count()
Returns the number of elements matching given selector.
|
default void |
dblclick()
This method double clicks the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to double click in the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set. |
void |
dblclick(Locator.DblclickOptions options)
This method double clicks the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to double click in the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set. |
default void |
dispatchEvent(String type)
The snippet below dispatches the
click event on the element. |
default void |
dispatchEvent(String type,
Object eventInit)
The snippet below dispatches the
click event on the element. |
void |
dispatchEvent(String type,
Object eventInit,
Locator.DispatchEventOptions options)
The snippet below dispatches the
click event on the element. |
default void |
dragTo(Locator target)
This method drags the locator to another target locator or target position.
|
void |
dragTo(Locator target,
Locator.DragToOptions options)
This method drags the locator to another target locator or target position.
|
default ElementHandle |
elementHandle()
Resolves given locator to the first matching DOM element.
|
ElementHandle |
elementHandle(Locator.ElementHandleOptions options)
Resolves given locator to the first matching DOM element.
|
List<ElementHandle> |
elementHandles()
Resolves given locator to all matching DOM elements.
|
default Object |
evaluate(String expression)
Returns the return value of
expression . |
default Object |
evaluate(String expression,
Object arg)
Returns the return value of
expression . |
Object |
evaluate(String expression,
Object arg,
Locator.EvaluateOptions options)
Returns the return value of
expression . |
default Object |
evaluateAll(String expression)
The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
to
expression . |
Object |
evaluateAll(String expression,
Object arg)
The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
to
expression . |
default JSHandle |
evaluateHandle(String expression)
Returns the return value of
expression as a JSHandle . |
default JSHandle |
evaluateHandle(String expression,
Object arg)
Returns the return value of
expression as a JSHandle . |
JSHandle |
evaluateHandle(String expression,
Object arg,
Locator.EvaluateHandleOptions options)
Returns the return value of
expression as a JSHandle . |
default void |
fill(String value)
This method waits for actionability checks, focuses the
element, fills it and triggers an
input event after filling. |
void |
fill(String value,
Locator.FillOptions options)
This method waits for actionability checks, focuses the
element, fills it and triggers an
input event after filling. |
default Locator |
filter()
This method narrows existing locator according to the options, for example filters by text.
|
Locator |
filter(Locator.FilterOptions options)
This method narrows existing locator according to the options, for example filters by text.
|
Locator |
first()
Returns locator to the first matching element.
|
default void |
focus()
Calls focus on the element.
|
void |
focus(Locator.FocusOptions options)
Calls focus on the element.
|
FrameLocator |
frameLocator(String selector)
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
that iframe:
|
default String |
getAttribute(String name)
Returns element attribute value.
|
String |
getAttribute(String name,
Locator.GetAttributeOptions options)
Returns element attribute value.
|
default Locator |
getByAltText(Pattern text)
Allows locating elements by their alt text.
|
Locator |
getByAltText(Pattern text,
Locator.GetByAltTextOptions options)
Allows locating elements by their alt text.
|
default Locator |
getByAltText(String text)
Allows locating elements by their alt text.
|
Locator |
getByAltText(String text,
Locator.GetByAltTextOptions options)
Allows locating elements by their alt text.
|
default Locator |
getByLabel(Pattern text)
Allows locating input elements by the text of the associated label.
|
Locator |
getByLabel(Pattern text,
Locator.GetByLabelOptions options)
Allows locating input elements by the text of the associated label.
|
default Locator |
getByLabel(String text)
Allows locating input elements by the text of the associated label.
|
Locator |
getByLabel(String text,
Locator.GetByLabelOptions options)
Allows locating input elements by the text of the associated label.
|
default Locator |
getByPlaceholder(Pattern text)
Allows locating input elements by the placeholder text.
|
Locator |
getByPlaceholder(Pattern text,
Locator.GetByPlaceholderOptions options)
Allows locating input elements by the placeholder text.
|
default Locator |
getByPlaceholder(String text)
Allows locating input elements by the placeholder text.
|
Locator |
getByPlaceholder(String text,
Locator.GetByPlaceholderOptions options)
Allows locating input elements by the placeholder text.
|
default Locator |
getByRole(AriaRole role)
|
Locator |
getByRole(AriaRole role,
Locator.GetByRoleOptions options)
|
Locator |
getByTestId(String testId)
Locate element by the test id.
|
default Locator |
getByText(Pattern text)
Allows locating elements that contain given text.
|
Locator |
getByText(Pattern text,
Locator.GetByTextOptions options)
Allows locating elements that contain given text.
|
default Locator |
getByText(String text)
Allows locating elements that contain given text.
|
Locator |
getByText(String text,
Locator.GetByTextOptions options)
Allows locating elements that contain given text.
|
default Locator |
getByTitle(Pattern text)
Allows locating elements by their title.
|
Locator |
getByTitle(Pattern text,
Locator.GetByTitleOptions options)
Allows locating elements by their title.
|
default Locator |
getByTitle(String text)
Allows locating elements by their title.
|
Locator |
getByTitle(String text,
Locator.GetByTitleOptions options)
Allows locating elements by their title.
|
void |
highlight()
Highlight the corresponding element(s) on the screen.
|
default void |
hover()
This method hovers over the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to hover over the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
void |
hover(Locator.HoverOptions options)
This method hovers over the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.mouse() to hover over the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
default String |
innerHTML()
Returns the
element.innerHTML . |
String |
innerHTML(Locator.InnerHTMLOptions options)
Returns the
element.innerHTML . |
default String |
innerText()
Returns the
element.innerText . |
String |
innerText(Locator.InnerTextOptions options)
Returns the
element.innerText . |
default String |
inputValue()
Returns
input.value for the selected <input> or <textarea> or <select> element. |
String |
inputValue(Locator.InputValueOptions options)
Returns
input.value for the selected <input> or <textarea> or <select> element. |
default boolean |
isChecked()
Returns whether the element is checked.
|
boolean |
isChecked(Locator.IsCheckedOptions options)
Returns whether the element is checked.
|
default boolean |
isDisabled()
Returns whether the element is disabled, the opposite of enabled.
|
boolean |
isDisabled(Locator.IsDisabledOptions options)
Returns whether the element is disabled, the opposite of enabled.
|
default boolean |
isEditable()
Returns whether the element is editable.
|
boolean |
isEditable(Locator.IsEditableOptions options)
Returns whether the element is editable.
|
default boolean |
isEnabled()
Returns whether the element is enabled.
|
boolean |
isEnabled(Locator.IsEnabledOptions options)
Returns whether the element is enabled.
|
default boolean |
isHidden()
Returns whether the element is hidden, the opposite of visible.
|
boolean |
isHidden(Locator.IsHiddenOptions options)
Returns whether the element is hidden, the opposite of visible.
|
default boolean |
isVisible()
Returns whether the element is visible.
|
boolean |
isVisible(Locator.IsVisibleOptions options)
Returns whether the element is visible.
|
Locator |
last()
Returns locator to the last matching element.
|
default Locator |
locator(String selector)
The method finds an element matching the specified selector in the locator's subtree.
|
Locator |
locator(String selector,
Locator.LocatorOptions options)
The method finds an element matching the specified selector in the locator's subtree.
|
Locator |
nth(int index)
Returns locator to the n-th matching element.
|
Page |
page()
A page this locator belongs to.
|
default void |
press(String key)
Focuses the element, and then uses
Keyboard.down() and Keyboard.up() . |
void |
press(String key,
Locator.PressOptions options)
Focuses the element, and then uses
Keyboard.down() and Keyboard.up() . |
default byte[] |
screenshot()
This method captures a screenshot of the page, clipped to the size and position of a particular element matching the
locator.
|
byte[] |
screenshot(Locator.ScreenshotOptions options)
This method captures a screenshot of the page, clipped to the size and position of a particular element matching the
locator.
|
default void |
scrollIntoViewIfNeeded()
This method waits for actionability checks, then tries to
scroll element into view, unless it is completely visible as defined by IntersectionObserver's
ratio . |
void |
scrollIntoViewIfNeeded(Locator.ScrollIntoViewIfNeededOptions options)
This method waits for actionability checks, then tries to
scroll element into view, unless it is completely visible as defined by IntersectionObserver's
ratio . |
default List<String> |
selectOption(ElementHandle values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default List<String> |
selectOption(ElementHandle[] values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(ElementHandle[] values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(ElementHandle values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default List<String> |
selectOption(SelectOption values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default List<String> |
selectOption(SelectOption[] values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(SelectOption[] values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(SelectOption values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default List<String> |
selectOption(String values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default List<String> |
selectOption(String[] values)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(String[] values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
List<String> |
selectOption(String values,
Locator.SelectOptionOptions options)
This method waits for actionability checks, waits until all
specified options are present in the
<select> element and selects these options. |
default void |
selectText()
This method waits for actionability checks, then focuses
the element and selects all its text content.
|
void |
selectText(Locator.SelectTextOptions options)
This method waits for actionability checks, then focuses
the element and selects all its text content.
|
default void |
setChecked(boolean checked)
This method checks or unchecks an element by performing the following steps:
Ensure that matched element is a checkbox or a radio input.
|
void |
setChecked(boolean checked,
Locator.SetCheckedOptions options)
This method checks or unchecks an element by performing the following steps:
Ensure that matched element is a checkbox or a radio input.
|
default void |
setInputFiles(FilePayload files)
Sets the value of the file input to these file paths or files.
|
default void |
setInputFiles(FilePayload[] files)
Sets the value of the file input to these file paths or files.
|
void |
setInputFiles(FilePayload[] files,
Locator.SetInputFilesOptions options)
Sets the value of the file input to these file paths or files.
|
void |
setInputFiles(FilePayload files,
Locator.SetInputFilesOptions options)
Sets the value of the file input to these file paths or files.
|
default void |
setInputFiles(Path files)
Sets the value of the file input to these file paths or files.
|
default void |
setInputFiles(Path[] files)
Sets the value of the file input to these file paths or files.
|
void |
setInputFiles(Path[] files,
Locator.SetInputFilesOptions options)
Sets the value of the file input to these file paths or files.
|
void |
setInputFiles(Path files,
Locator.SetInputFilesOptions options)
Sets the value of the file input to these file paths or files.
|
default void |
tap()
This method taps the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.touchscreen() to tap the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
void |
tap(Locator.TapOptions options)
This method taps the element by performing the following steps:
Wait for actionability checks on the element, unless
force option is set.
Scroll the element into view if needed.
Use Page.touchscreen() to tap the center of the element, or the specified position .
Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
|
default String |
textContent()
Returns the
node.textContent . |
String |
textContent(Locator.TextContentOptions options)
Returns the
node.textContent . |
default void |
type(String text)
Focuses the element, and then sends a
keydown , keypress /input , and keyup event for each character in the text. |
void |
type(String text,
Locator.TypeOptions options)
Focuses the element, and then sends a
keydown , keypress /input , and keyup event for each character in the text. |
default void |
uncheck()
This method checks the element by performing the following steps:
Ensure that element is a checkbox or a radio input.
|
void |
uncheck(Locator.UncheckOptions options)
This method checks the element by performing the following steps:
Ensure that element is a checkbox or a radio input.
|
default void |
waitFor()
Returns when element specified by locator satisfies the
state option. |
void |
waitFor(Locator.WaitForOptions options)
Returns when element specified by locator satisfies the
state option. |
List<String> allInnerTexts()
node.innerText
values for all matching nodes.List<String> allTextContents()
node.textContent
values for all matching nodes.default void blur()
void blur(Locator.BlurOptions options)
default BoundingBox boundingBox()
null
if the element is not visible. The bounding box is
calculated relative to the main frame viewport - which is usually the same as the browser window.
Scrolling affects the returned bounding box, similarly to Element.getBoundingClientRect.
That means x
and/or y
may be negative.
Elements from child frames return the bounding box relative to the main frame, unlike the Element.getBoundingClientRect.
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following snippet should click the center of the element.
BoundingBox box = element.boundingBox();
page.mouse().click(box.x + box.width / 2, box.y + box.height / 2);
BoundingBox boundingBox(Locator.BoundingBoxOptions options)
null
if the element is not visible. The bounding box is
calculated relative to the main frame viewport - which is usually the same as the browser window.
Scrolling affects the returned bounding box, similarly to Element.getBoundingClientRect.
That means x
and/or y
may be negative.
Elements from child frames return the bounding box relative to the main frame, unlike the Element.getBoundingClientRect.
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following snippet should click the center of the element.
BoundingBox box = element.boundingBox();
page.mouse().click(box.x + box.width / 2, box.y + box.height / 2);
default void check()
force
option is set.Page.mouse()
to click in the center of the element.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
void check(Locator.CheckOptions options)
force
option is set.Page.mouse()
to click in the center of the element.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
default void clear()
input
event after clearing.
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
cleared instead.
void clear(Locator.ClearOptions options)
input
event after clearing.
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
cleared instead.
default void click()
force
option is set.Page.mouse()
to click in the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
void click(Locator.ClickOptions options)
force
option is set.Page.mouse()
to click in the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
int count()
default void dblclick()
force
option is set.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.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
NOTE: element.dblclick()
dispatches two click
events and a single dblclick
event.
void dblclick(Locator.DblclickOptions options)
force
option is set.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.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
NOTE: element.dblclick()
dispatches two click
events and a single dblclick
event.
default void dispatchEvent(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().
element.dispatchEvent("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 = page.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
element.dispatchEvent("dragstart", arg);
type
- DOM event type: "click"
, "dragstart"
, etc.eventInit
- Optional event-specific initialization properties.default void dispatchEvent(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().
element.dispatchEvent("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 = page.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
element.dispatchEvent("dragstart", arg);
type
- DOM event type: "click"
, "dragstart"
, etc.void dispatchEvent(String type, Object eventInit, Locator.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().
element.dispatchEvent("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 = page.evaluateHandle("() => new DataTransfer()");
Map<String, Object> arg = new HashMap<>();
arg.put("dataTransfer", dataTransfer);
element.dispatchEvent("dragstart", arg);
type
- DOM event type: "click"
, "dragstart"
, etc.eventInit
- Optional event-specific initialization properties.default void dragTo(Locator target)
mousedown
, then move to the target element or position and perform a mouseup
.
Locator source = page.locator("#source");
Locator target = page.locator("#target");
source.dragTo(target);
// or specify exact positions relative to the top-left corners of the elements:
source.dragTo(target, new Locator.DragToOptions()
.setSourcePosition(34, 7).setTargetPosition(10, 20));
target
- Locator of the element to drag to.void dragTo(Locator target, Locator.DragToOptions options)
mousedown
, then move to the target element or position and perform a mouseup
.
Locator source = page.locator("#source");
Locator target = page.locator("#target");
source.dragTo(target);
// or specify exact positions relative to the top-left corners of the elements:
source.dragTo(target, new Locator.DragToOptions()
.setSourcePosition(34, 7).setTargetPosition(10, 20));
target
- Locator of the element to drag to.default ElementHandle elementHandle()
ElementHandle elementHandle(Locator.ElementHandleOptions options)
List<ElementHandle> elementHandles()
default Object evaluate(String expression, Object arg)
expression
.
This method passes this handle as the first argument to expression
.
If expression
returns a Promise, then
handle.evaluate
would wait for the promise to resolve and return its value.
Examples:
Locator tweets = page.locator(".tweet .retweets");
assertEquals("10 retweets", tweets.evaluate("node => node.innerText"));
expression
- 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 to expression
.default Object evaluate(String expression)
expression
.
This method passes this handle as the first argument to expression
.
If expression
returns a Promise, then
handle.evaluate
would wait for the promise to resolve and return its value.
Examples:
Locator tweets = page.locator(".tweet .retweets");
assertEquals("10 retweets", tweets.evaluate("node => node.innerText"));
expression
- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
automatically invoked.Object evaluate(String expression, Object arg, Locator.EvaluateOptions options)
expression
.
This method passes this handle as the first argument to expression
.
If expression
returns a Promise, then
handle.evaluate
would wait for the promise to resolve and return its value.
Examples:
Locator tweets = page.locator(".tweet .retweets");
assertEquals("10 retweets", tweets.evaluate("node => node.innerText"));
expression
- 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 to expression
.default Object evaluateAll(String expression)
expression
. Returns the result of expression
invocation.
If expression
returns a Promise, then Locator.evaluateAll()
would wait for the promise to resolve and return its value.
Examples:
Locator elements = page.locator("div");
boolean divCounts = (boolean) elements.evaluateAll("(divs, min) => divs.length >= min", 10);
expression
- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
automatically invoked.Object evaluateAll(String expression, Object arg)
expression
. Returns the result of expression
invocation.
If expression
returns a Promise, then Locator.evaluateAll()
would wait for the promise to resolve and return its value.
Examples:
Locator elements = page.locator("div");
boolean divCounts = (boolean) elements.evaluateAll("(divs, min) => divs.length >= min", 10);
expression
- 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 to expression
.default JSHandle evaluateHandle(String expression, Object arg)
expression
as a JSHandle
.
This method passes this handle as the first argument to expression
.
The only difference between Locator.evaluate()
and Locator.evaluateHandle()
is that Locator.evaluateHandle()
returns JSHandle
.
If the function passed to the Locator.evaluateHandle()
returns a Promise, then Locator.evaluateHandle()
would wait for the promise to resolve and return its value.
See Page.evaluateHandle()
for more details.
expression
- 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 to expression
.default JSHandle evaluateHandle(String expression)
expression
as a JSHandle
.
This method passes this handle as the first argument to expression
.
The only difference between Locator.evaluate()
and Locator.evaluateHandle()
is that Locator.evaluateHandle()
returns JSHandle
.
If the function passed to the Locator.evaluateHandle()
returns a Promise, then Locator.evaluateHandle()
would wait for the promise to resolve and return its value.
See Page.evaluateHandle()
for more details.
expression
- JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is
automatically invoked.JSHandle evaluateHandle(String expression, Object arg, Locator.EvaluateHandleOptions options)
expression
as a JSHandle
.
This method passes this handle as the first argument to expression
.
The only difference between Locator.evaluate()
and Locator.evaluateHandle()
is that Locator.evaluateHandle()
returns JSHandle
.
If the function passed to the Locator.evaluateHandle()
returns a Promise, then Locator.evaluateHandle()
would wait for the promise to resolve and return its value.
See Page.evaluateHandle()
for more details.
expression
- 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 to expression
.default void fill(String value)
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 Locator.type()
.
value
- Value to set for the <input>
, <textarea>
or [contenteditable]
element.void fill(String value, Locator.FillOptions options)
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 Locator.type()
.
value
- Value to set for the <input>
, <textarea>
or [contenteditable]
element.default Locator filter()
Locator rowLocator = page.locator("tr");
// ...
rowLocator
.filter(new Locator.FilterOptions().setHasText("text in column 1"))
.filter(new Locator.FilterOptions().setHas(
page.getByRole("button", new Page.GetByRoleOptions().setName("column 2 button"))
))
.screenshot();
Locator filter(Locator.FilterOptions options)
Locator rowLocator = page.locator("tr");
// ...
rowLocator
.filter(new Locator.FilterOptions().setHasText("text in column 1"))
.filter(new Locator.FilterOptions().setHas(
page.getByRole("button", new Page.GetByRoleOptions().setName("column 2 button"))
))
.screenshot();
Locator first()
default void focus()
void focus(Locator.FocusOptions options)
FrameLocator frameLocator(String selector)
Locator locator = page.frameLocator("iframe").getByText("Submit");
locator.click();
selector
- A selector to use when resolving DOM element. See working with
selectors for more details.default String getAttribute(String name)
name
- Attribute name to get the value for.String getAttribute(String name, Locator.GetAttributeOptions options)
name
- Attribute name to get the value for.default Locator getByAltText(String text)
text
- Text to locate the element for.Locator getByAltText(String text, Locator.GetByAltTextOptions options)
text
- Text to locate the element for.default Locator getByAltText(Pattern text)
text
- Text to locate the element for.Locator getByAltText(Pattern text, Locator.GetByAltTextOptions options)
text
- Text to locate the element for.default Locator getByLabel(String text)
text
- Text to locate the element for.Locator getByLabel(String text, Locator.GetByLabelOptions options)
text
- Text to locate the element for.default Locator getByLabel(Pattern text)
text
- Text to locate the element for.Locator getByLabel(Pattern text, Locator.GetByLabelOptions options)
text
- Text to locate the element for.default Locator getByPlaceholder(String text)
text
- Text to locate the element for.Locator getByPlaceholder(String text, Locator.GetByPlaceholderOptions options)
text
- Text to locate the element for.default Locator getByPlaceholder(Pattern text)
text
- Text to locate the element for.Locator getByPlaceholder(Pattern text, Locator.GetByPlaceholderOptions options)
text
- Text to locate the element for.default Locator getByRole(AriaRole role)
Note that 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 role
and/or aria-*
attributes to default values.
role
- Required aria role.Locator getByRole(AriaRole role, Locator.GetByRoleOptions options)
Note that 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 role
and/or aria-*
attributes to default values.
role
- Required aria role.Locator getByTestId(String testId)
data-testid
attribute is used as a test id. Use Selectors.setTestIdAttribute()
to configure a different test id attribute if necessary.testId
- Id to locate the element by.default Locator getByText(String text)
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))
See also Locator.filter()
that allows to match by another criteria, like an accessible role, and
then filter by the text content.
NOTE: 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.
NOTE: Input elements of the type button
and submit
are matched by their value
instead of the text content. For example,
locating by text "Log in"
matches <input type=button value="Log in">
.
text
- Text to locate the element for.Locator getByText(String text, Locator.GetByTextOptions options)
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))
See also Locator.filter()
that allows to match by another criteria, like an accessible role, and
then filter by the text content.
NOTE: 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.
NOTE: Input elements of the type button
and submit
are matched by their value
instead of the text content. For example,
locating by text "Log in"
matches <input type=button value="Log in">
.
text
- Text to locate the element for.default Locator getByText(Pattern text)
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))
See also Locator.filter()
that allows to match by another criteria, like an accessible role, and
then filter by the text content.
NOTE: 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.
NOTE: Input elements of the type button
and submit
are matched by their value
instead of the text content. For example,
locating by text "Log in"
matches <input type=button value="Log in">
.
text
- Text to locate the element for.Locator getByText(Pattern text, Locator.GetByTextOptions options)
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))
See also Locator.filter()
that allows to match by another criteria, like an accessible role, and
then filter by the text content.
NOTE: 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.
NOTE: Input elements of the type button
and submit
are matched by their value
instead of the text content. For example,
locating by text "Log in"
matches <input type=button value="Log in">
.
text
- Text to locate the element for.default Locator getByTitle(String text)
text
- Text to locate the element for.Locator getByTitle(String text, Locator.GetByTitleOptions options)
text
- Text to locate the element for.default Locator getByTitle(Pattern text)
text
- Text to locate the element for.Locator getByTitle(Pattern text, Locator.GetByTitleOptions options)
text
- Text to locate the element for.void highlight()
Locator.highlight()
.default void hover()
force
option is set.Page.mouse()
to hover over the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
void hover(Locator.HoverOptions options)
force
option is set.Page.mouse()
to hover over the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
default String innerHTML()
element.innerHTML
.String innerHTML(Locator.InnerHTMLOptions options)
element.innerHTML
.default String innerText()
element.innerText
.String innerText(Locator.InnerTextOptions options)
element.innerText
.default String inputValue()
input.value
for 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.
String inputValue(Locator.InputValueOptions options)
input.value
for 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.
default boolean isChecked()
boolean isChecked(Locator.IsCheckedOptions options)
default boolean isDisabled()
boolean isDisabled(Locator.IsDisabledOptions options)
default boolean isEditable()
boolean isEditable(Locator.IsEditableOptions options)
default boolean isEnabled()
boolean isEnabled(Locator.IsEnabledOptions options)
default boolean isHidden()
boolean isHidden(Locator.IsHiddenOptions options)
default boolean isVisible()
boolean isVisible(Locator.IsVisibleOptions options)
Locator last()
default Locator locator(String selector)
Locator.filter()
method.
selector
- A selector to use when resolving DOM element. See working with
selectors for more details.Locator locator(String selector, Locator.LocatorOptions options)
Locator.filter()
method.
selector
- A selector to use when resolving DOM element. See working with
selectors for more details.Locator nth(int index)
nth(0)
selects the first element.Page page()
default void press(String key)
Keyboard.down()
and Keyboard.up()
.
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.
key
- Name of the key to press or a character to generate, such as ArrowLeft
or a
.void press(String key, Locator.PressOptions options)
Keyboard.down()
and Keyboard.up()
.
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.
key
- Name of the key to press or a character to generate, such as ArrowLeft
or a
.default byte[] screenshot()
This method waits for the actionability checks, then scrolls element into view before taking a screenshot. If the element is detached from DOM, the method throws an error.
Returns the buffer with the captured screenshot.
byte[] screenshot(Locator.ScreenshotOptions options)
This method waits for the actionability checks, then scrolls element into view before taking a screenshot. If the element is detached from DOM, the method throws an error.
Returns the buffer with the captured screenshot.
default void scrollIntoViewIfNeeded()
ratio
.void scrollIntoViewIfNeeded(Locator.ScrollIntoViewIfNeededOptions options)
ratio
.default List<String> selectOption(String values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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 values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(ElementHandle values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(ElementHandle values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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[] values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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[] values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(SelectOption values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(SelectOption values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(ElementHandle[] values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(ElementHandle[] values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(SelectOption[] values)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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(SelectOption[] values, Locator.SelectOptionOptions options)
<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
element.selectOption("blue");
// single selection matching the label
element.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
element.selectOption(new String[] {"red", "green", "blue"});
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 selectText()
If the element is inside the <label>
element that has an associated control, focuses and selects text
in the control instead.
void selectText(Locator.SelectTextOptions options)
If the element is inside the <label>
element that has an associated control, focuses and selects text
in the control instead.
default void setChecked(boolean checked)
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.
checked
- Whether to check or uncheck the checkbox.void setChecked(boolean checked, Locator.SetCheckedOptions options)
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.
checked
- Whether to check or uncheck the checkbox.default void setInputFiles(Path files)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
void setInputFiles(Path files, Locator.SetInputFilesOptions options)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
default void setInputFiles(Path[] files)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
void setInputFiles(Path[] files, Locator.SetInputFilesOptions options)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
default void setInputFiles(FilePayload files)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
void setInputFiles(FilePayload files, Locator.SetInputFilesOptions options)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
default void setInputFiles(FilePayload[] files)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
void setInputFiles(FilePayload[] files, Locator.SetInputFilesOptions options)
filePaths
are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
This method expects Locator
to point to an input element. However, if the element is
inside the <label>
element that has an associated control, targets the control
instead.
default void tap()
force
option is set.Page.touchscreen()
to tap the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
NOTE: element.tap()
requires that the hasTouch
option of the browser context be set to true.
void tap(Locator.TapOptions options)
force
option is set.Page.touchscreen()
to tap the center of the element, or the specified position
.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
NOTE: element.tap()
requires that the hasTouch
option of the browser context be set to true.
default String textContent()
node.textContent
.String textContent(Locator.TextContentOptions options)
node.textContent
.default void type(String text)
keydown
, keypress
/input
, and keyup
event for each character in the text.
To press a special key, like Control
or ArrowDown
, use Locator.press()
.
element.type("Hello"); // Types instantly
element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
An example of typing into a text field and then submitting the form:
Locator element = page.getByLabel("Password");
element.type("my password");
element.press("Enter");
text
- A text to type into a focused element.void type(String text, Locator.TypeOptions options)
keydown
, keypress
/input
, and keyup
event for each character in the text.
To press a special key, like Control
or ArrowDown
, use Locator.press()
.
element.type("Hello"); // Types instantly
element.type("World", new Locator.TypeOptions().setDelay(100)); // Types slower, like a user
An example of typing into a text field and then submitting the form:
Locator element = page.getByLabel("Password");
element.type("my password");
element.press("Enter");
text
- A text to type into a focused element.default void uncheck()
force
option is set.Page.mouse()
to click in the center of the element.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
void uncheck(Locator.UncheckOptions options)
force
option is set.Page.mouse()
to click in the center of the element.noWaitAfter
option is set.If the element is detached from the DOM at any moment during the action, this method throws.
When all steps combined have not finished during the specified timeout
, this method throws a TimeoutError
. Passing
zero timeout disables this.
default void waitFor()
state
option.
If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to timeout
milliseconds until the condition is met.
Locator orderSent = page.locator("#order-sent");
orderSent.waitFor();
void waitFor(Locator.WaitForOptions options)
state
option.
If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to timeout
milliseconds until the condition is met.
Locator orderSent = page.locator("#order-sent");
orderSent.waitFor();
Copyright © 2022. All rights reserved.