- Text input
- Checkboxes and radio buttons
- Select options
- Mouse click
- Type characters
- Keys and shortcuts
- Upload files
- Focus element
This is the easiest way to fill out the form fields. It focuses the element and triggers an
input event with the entered text. It works for
<label> associated with an input or textarea.
- Page.FillAsync(selector, value, options)
- Frame.FillAsync(selector, value, options)
- ElementHandle.FillAsync(value, options)
This is the easiest way to check and uncheck a checkbox or a radio button. This method can be used with
label associated with checkbox or radio button.
- Page.CheckAsync(selector, options)
- Page.IsCheckedAsync(selector, options)
- Page.UncheckAsync(selector, options)
Selects one or multiple options in the
<select> element. You can specify option
elementHandle to select. Multiple options can be selected.
- Page.SelectOptionAsync(selector, values, options)
- Frame.SelectOptionAsync(selector, values, options)
- ElementHandle.SelectOptionAsync(values, options)
Performs a simple human click.
Under the hood, this and other pointer-related methods:
- wait for element with given selector to be in DOM
- wait for it to become displayed, i.e. not empty, no
- wait for it to stop moving, for example, until css transition finishes
- scroll the element into view
- wait for it to receive pointer events at the action point, for example, waits until element becomes non-obscured by other elements
- retry if the element is detached during any of the above checks
Sometimes, apps use non-trivial logic where hovering the element overlays it with another element that intercepts the click. This behavior is indistinguishable from a bug where element gets covered and the click is dispatched elsewhere. If you know this is taking place, you can bypass the actionability checks and force the click:
If you are not interested in testing your app under the real conditions and want to simulate the click by any means possible, you can trigger the
HTMLElement.click() behavior via simply dispatching a click event on the element:
- Page.ClickAsync(selector, options)
- Frame.ClickAsync(selector, options)
- Page.DblClickAsync(selector, options)
- Frame.DblClickAsync(selector, options)
- Page.HoverAsync(selector, options)
- Frame.HoverAsync(selector, options)
- Page.DispatchEventAsync(selector, type, eventInit, options)
- Frame.DispatchEventAsync(selector, type, eventInit, options)
- ElementHandle.DispatchEventAsync(type, eventInit)
Type into the field character by character, as if it was a user with a real keyboard.
This method will emit all the necessary keyboard events, with all the
keypress events in place. You can even specify the optional
delay between the key presses to simulate real user behavior.
Most of the time, Page.FillAsync(selector, value, options) will just work. You only need to type characters if there is special keyboard handling on the page.
- Page.TypeAsync(selector, text, options)
- Frame.TypeAsync(selector, text, options)
- ElementHandle.TypeAsync(text, options)
- Keyboard.TypeAsync(text, options)
This method focuses the selected element and produces a single keystroke. It accepts the logical key names that are emitted in the keyboardEvent.key property of the keyboard events:
- You can alternatively specify a single character you'd like to produce such as
- Following modification shortcuts are also supported:
Shift, Control, Alt, Meta.
Simple version produces a single character. This character is case-sensitive, so
"A" will produce different results.
Shortcuts such as
"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.
Note that you still need to specify the capital
Shift-A to produce the capital character.
Shift-a produces a lower-case one as if you had the
- Page.PressAsync(selector, key, options)
- Frame.PressAsync(selector, key, options)
- ElementHandle.PressAsync(key, options)
- Keyboard.PressAsync(key, options)
You can select input files for upload using the Page.SetInputFilesAsync(selector, files, options) method. It expects first argument to point to an input element with the type
"file". Multiple files can be passed in the array. If some of the file paths are relative, they are resolved relative to the current working directory. Empty array clears the selected files.
If you don't have input element in hand (it is created dynamically), you can handle the event Page.FileChooser event or use a corresponding waiting method upon your action:
- Page.SetInputFilesAsync(selector, files, options)
- Frame.SetInputFilesAsync(selector, files, options)
- ElementHandle.SetInputFilesAsync(files, options)
For the dynamic pages that handle focus events, you can focus the given element.