Block reference / Web interaction
Press key
Send a key, or a string of keys, to an element or to whatever has focus.
Only in
WarpX Browser
Press key sends keyboard events into the page: a single key such as Enter or Escape, a combination such as Control+a, or a run of characters. Use it to submit a simple search form, close a dialog that listens for Escape, trigger a page's own keyboard shortcut, or step through a list with the arrow keys. To enter text into a field, Type text and Forms are more reliable.
Settings
- Target element (Optional)
The element that gets the keys, as a CSS selector or XPath. The target button picks it in the profile's browser. Leave it empty to send the keys to whatever has focus. Without Debug mode, the block looks once and does not wait; if nothing matches, it fails with an element-not-found error and sends no keys. With Debug mode on, the target is focused first, and one that matches nothing fails the block too.
Exampleinput[name="q"]- Action
Press a key sends one key. Press multiple keys sends a string of characters, one after another.
ExamplePress a key- Keywhen Action is Press a key
A key name such as
Enter,Escape,Tab,ArrowDownora, or a combination joined with+, such asControl+aorShift+Tab. The keys go down in the order written and come up in reverse, and each event carries the flags of the modifiers held;Control++is Control with the+key. The button next to it records the next key you press.ExampleEnter- keyswhen Action is Press multiple keys
The characters to send. It takes references such as
{{variables.searchTerm}}. In a text field or editable element the text is added after what is already there. Anywhere else each character is sent as its own key press.Example{{variables.searchTerm}}- Press time (milliseconds)
With Press a key, how long the keys stay down before they are released, in milliseconds. With Press multiple keys, the pause between characters.
0releases at once.Example0- Delay time (ms)
How long to wait after the block finishes, in milliseconds. Write a range such as
1000,3000to pick a random wait in it each run.Example1500
Every block also has the shared block settings — a description, Disable block and what to do on an error. Fields that take text accept data from earlier blocks.
What it hands on
Writes nothing to the table or variables, and leaves by its single output. It fails when Target element (Optional) is filled in and finds nothing.
Example: Submit a search box with Enter
- Start
- Open URL
- Type text
- Press key
- Add Open URL after Start with
https://forum.example.com/search. - Add Type text with
input[name="q"]and the textproxy rotation. - Add Press key. Set Target element (Optional) to
input[name="q"]. Type text leaves the field without focus, so name it here. - Keep Action on Press a key and set Key to
Enter. - Set Delay time (ms) to
1500to give the results page time to load. - Run the workflow. The search form is sent and the results page opens.
Good to know
- Without Debug mode, the keys are events created by script in the page. The page's own key listeners see them, but the browser does not act on them:
Tabdoes not move the focus, and a browser shortcut such asControl+adoes not select anything. A page that listens for the shortcut itself, such asControl+kfor its search box, does react. - Without Debug mode, no character is typed into a field while Control, Alt or Meta is held:
Control+asends the events and leaves the field's text as it is. - Without Debug mode,
Enterin a text field inside a form submits the form the way a person's Enter does: the form's submit event fires, so the page's own submit handling and the browser's field checks run. A form the page blocks, for example because a required field is empty, is not sent. - Without Debug mode, a single letter sent with Press a key into a text field is added to its value without the input event frameworks listen for. Use Type text for text.
- Turn on Debug mode in the block's settings to send the keys as real keyboard input from the browser itself, as a person's keys are. The page sees trusted events (
isTrustedistrue), and the browser acts on them:Tabmoves the focus andControl+aselects the text. A combination is held down in the order written for Press time (milliseconds), then released in reverse. Press multiple keys types the text with Press time (milliseconds) between keys. - The keys are not paced like a person's typing beyond Press time (milliseconds), and Human Emulation is not offered on this block.
See also
- Type text — Put text into an input, textarea or editable element.
- Trigger event — Fire a DOM event such as change, mouseover or keydown on an element.
- Forms — Fill a text field, choose a dropdown option, or tick a checkbox or radio button.
- Click element — Click an element on the page, with human-like mouse movement by default.