How do I make the protractor press the ESCAPE key?

I've tried this:

browser.actions().sendKeys(protractor.Key.ESCAPE).perform();

      

but nothing happens.

I use this with SPACE Key and it works great.

browser.actions().sendKeys(protractor.Key.SPACE).perform();

      

+3


source to share


4 answers


There could be several reasons for this, but first of all, according to the Protractor documentation, you need to execute sendKeys()

on ElementFinder

, so if focus is on, like 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 ( $

= transcript for by.css

):



$('body').sendKeys(protractor.Key.ESCAPE);

      

Second, there might be a problem with your web editor's UserInteraction API. There have been many issues in the past with Firefox and Safari drivers and some versions of Chromedriver.

Hope it helps

+7


source


Maybe you should send an ESC key to any item? In my application, the following job works fine for a cancel button.



element(by.xpath('...')).sendKeys(protractor.Key.ESCAPE);

      

+3


source


In such confusion, start looking for source code .. make a .log console to get an idea of โ€‹โ€‹what the framework envisions.

try it

console.log('**********');
console.log(protractor.Key);
console.log('**********');

      

+1


source


If you want to use the same code as yours, you can use this:

browser.actions().sendKeys(protractor.Key.ESC).perform();

      

I hope this works for you.

Since sendKeys and Key are implemented using the Keyboard class, the key values โ€‹โ€‹will be different for the OS. May be.

The links below will list the names of the keys you must provide for sendKeys:
https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm https://autohotkey.com/docs/commands/Send.htm

Hope it helped.

0


source







All Articles