• +43 660 1453541
  • contact@germaniumhq.com

How to Type Keys Using Germanium


How to Type Keys Using Germanium

One of the most common interactions in browsers is writing keys. Germanium has a trivially simple API to type keys, that includes shortcut handling, and special keys such as <Enter>. Here’s how:

It’s compatible with sendKeys() from Selenium. What it handles better is shortcuts. So when you type something like:

type_keys("hi<enter>Mark!")

This creates the 3 required selenium commands: sendKeys("hi"), keyPress(Key.ENTER), and sendKeys('Mark!'), chains them into an action chain, and executes the action chain.

But wait that’s more!

What’s even better is that it works even for complex shortcuts such as <ctrl-a>, or <ctrl-shift-a>, leaving us with readable code that’s self explanatory. So instead of fighting with the Selenium API, we’re left with focusing on our problem domain.

We can use shortcuts for clearing inputs:

type_keys('<c-a><del>input')`

trying out copy-paste:

type_keys('<ctrl-v>')

or editor commands such as bold:

type_keys('normal<ctrl-b>bold<ctrl-b>normal')

Neat!

Type away!