Reputation: 369
I've tried this:
browser.actions().sendKeys(protractor.Key.ESCAPE).perform();
but nothing happens.
I'm using this with SPACE Key and this works fine.
browser.actions().sendKeys(protractor.Key.SPACE).perform();
Upvotes: 8
Views: 11241
Reputation:
selectEscapeKey: function () { return browser.actions().sendKeys(protractor.Key.ESCAPE).perform();},
Upvotes: 0
Reputation: 696
If you want to use the same code as you have return, you can use this:
browser
.actions()
.sendKeys(protractor.Key.ESCAPE)
.perform();
I hope this would work for you.
Since the sendKeys and Key is implemented using Keyboard class, the key values will differ for the OS May be.
The links below will give the name of the keys you have to give for the sendKeys:
https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
https://autohotkey.com/docs/commands/Send.htm
Hope this helped.
Upvotes: 6
Reputation: 2375
There could be several reasons for it, but first of all, according to the documentation of Protractor you need to execute the sendKeys()
on an ElementFinder
, so if the focus is on for example an input field you can do this
element(by.css('#-your-input-id')).sendKeys(protractor.Key.ESCAPE);
You can also do it on the body like this ($
= shorthand for by.css
):
$('body').sendKeys(protractor.Key.ESCAPE);
Secondly there could be a problem with the UserInteraction API of your webdriver. In the past there were a lot of problems with the Firefox and Safari driver and with some versions of Chromedriver.
Hope this helps
Upvotes: 13
Reputation: 1375
When in confusion like this, start looking into the source code..else do a console.log to get idea of what is provided by the framework.
Try this
console.log('**********');
console.log(protractor.Key);
console.log('**********');
Upvotes: 0
Reputation: 765
Maybe you must send the ESC Key to any element? At my app the following assignment works fine for a cancel button.
element(by.xpath('...')).sendKeys(protractor.Key.ESCAPE);
Upvotes: 3