Sending Special Keys to Elements with Protractor sendKeys()

It is pretty straight-forward from the examples on the web how to send alphanumeric keystrokes to an element with protractor.  It gets a bit trickier if you want to send a special key.  If you are lucky you will find a forum post with the key you are after. I wanted to send a right-arrow key and couldn't find anything on the Protractor site or in any forum posts.

I searched for ages before I found this lifesaving webpage.  It lists the constants for all the special keys. Find the constant name in this webpage and then prepend "protractor.Key." to it.

https://gist.github.com/boxmein/f86b6e196d3c0c472f302c80f7388704

So to send the right arrow key to an input field (useful for editing an input with existing content) ..

element(by.tagName('input')).sendKeys(protractor.Key.ARROW_RIGHT);

Comments

Popular posts from this blog

Git Cheat Sheet