Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Ctrl+A combination to an element

I'm using protractor for angular end-to-end aka e2e testing.

In order to send keys to an element, I use:

element(by.model('myModel')).sendKeys('Test'); 

How can I send a combination of keys, like Ctrl+A?


I've searched through protractor source code at github, but haven't found a relevant example.

like image 857
alecxe Avatar asked Aug 14 '14 04:08

alecxe


2 Answers

It's perfectly possible in Linux and Windows but not in OSX

var elm = element(by.model('myModel')); elm.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "a")); 

There is also a non-element variant:

browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('a').perform(); 
like image 107
Leo Gallucci Avatar answered Sep 28 '22 18:09

Leo Gallucci


If you use protractor-hotkeys, you can use simple hotkey strings (like those from angular-hotkeys) to trigger them in protractor tests.

So, this would become:

var hotkeys = require('protractor-hotkeys'); hotkeys.trigger('ctrl+a', { targetElement: element(by.model('myModel')) }); 
like image 44
yurisich Avatar answered Sep 28 '22 17:09

yurisich