Keyboard¶
Using the methods below, you can control and obtain information from the keyboard.
Writing text¶
You can write text in a couple of different ways depending on the behaviour that you want to simulate.
Human-like typing¶
Using this method you can simulate a human typing text key by key.
Pasting the text all at once¶
The paste
method is fast and widely used but the difference is that it
just pastes the contents of the clipboard.
Tip
Some fields such as selection boxes (ComboBox widgets) or some web forms
don't allow the paste
operation. To overcome issues like that, use the Human-like
method described above.
Pressing keyboard keys¶
You can press keys on the keyboard to activate shortcuts and perform other operations.
Tab¶
The tab
method press key Tab of keyboard.
Enter¶
The enter
method press the key Enter on the keyboard.
Tip
This method can often be used to replace a click or interaction with a button through computer vision.
Escape/Esc¶
Space¶
Backspace¶
Delete¶
Shift¶
The Shift key can be held down and released as to simulate a magnitude of behaviours depending on the process that you are automating.
To demonstrate, we are going to hold
the Shift key and type a text to make the text uppercase.
We will also release
the Shift key and type the same text in lowercase.
# Press and hold shift.
bot.hold_shift()
# Type the text "test", noting that the text is rendered in uppercase.
bot.type_key("test uppercase")
# Realese shift.
bot.release_shift()
# take a space to type new text.
bot.space(wait=1000)
# Type the text "test", noting that the text is rendered in lowercase, because was used the method release shift earlier.
bot.type_key("test lowercase")
// Press and hold shift.
holdShift();
// Type the text "test", noting that the text is rendered in uppercase.
type("test uppercase");
// Realese shift.
releaseShift();
// take a space to type new text.
space(1000);
// Type the text "test", noting that the text is rendered in lowercase, because was used the method release shift earlier.
type("test lowercase");
Directional keys¶
With the methods below, we can interact, or press the keyboard directional keys (up, down, left and right).
# On the directional keyboard, press the up key, up arrow.
bot.type_up()
# On the directional keyboard, press the down key, down arrow.
bot.type_down()
# On the directional keyboard, press the left key, left arrow.
bot.type_left()
# On the directional keyboard, press the right key, right arrow.
bot.type_right()
Page Up
and Page Down
¶
Keyboard shortcuts¶
The framework has the most used shortcuts ready to use.
In the event that we missed one you can use the type keys
method to press any list of keys and simulate any shortcut.
Warning
You must use keys and shortcuts that are compatible with the browser context.
Using type keys for shortcuts¶
You can also pass the key reference you need to use via Selenium's Keys
class.