How to use key press events in nightwatch js ?

7,626 views
Skip to first unread message

Aravindhan S

unread,
May 24, 2016, 6:22:55 AM5/24/16
to NightwatchJs
Hey,

I have a case where I need to press "Enter" button to navigate on my web application (System under test).

I did achieved this using Selenium- Java using Robot class, 

Robot robot = new Robot();
 robot
.keyPress(KeyEvent.VK_ENTER);
 robot
.keyRelease(KeyEvent.VK_ENTER);


Can I do the same using nightwatch js ? 
Message has been deleted

Eric Mumford

unread,
Jun 7, 2016, 12:38:24 AM6/7/16
to NightwatchJs
There's about 100 different ways to respond to your question and all of them are wrong depending on your situation.

At a high level, sure, Nightwatch and 50 other frameworks can send keypresses to your System Under Test.

The larger question is what goal are you trying to accomplish, what are your constraints, what have you tried, and what specific questions do you have about what you've tried?

Ashish Jain

unread,
Jul 26, 2016, 8:38:10 AM7/26/16
to NightwatchJs
But can you press keyboard button "T" in this way?

Ashish Jain

unread,
Jul 27, 2016, 4:25:15 AM7/27/16
to NightwatchJs
Hi

I have answer, You can try following way to press any key in nightwatch.js, i am pressing T and it is working superb!!

client.keys("t", function(done) {
    client.pause(5000);
    client.expect.element('#carousel_container').to.have.css('display').which.equals('block');
});

Ashish Jain

unread,
Jul 27, 2016, 4:32:39 AM7/27/16
to NightwatchJs
You can try following way to press any key in nightwatch.js, i am pressing T and it is working superb!!

client.keys("t", function(done) {
client.pause(5000);
client.expect.element('#carousel_container').to.have.css('display').which.equals('block');
});

we are using above way because nightwatch.js Keys does not have any alphabet command in it's array, i have consoled and i haven't found any alphabet to press it.

Keys:
{ NULL: '',
CANCEL: '',
HELP: '',
BACK_SPACE: '',
TAB: '',
CLEAR: '',
RETURN: '',
ENTER: '',
SHIFT: '',
CONTROL: '',
ALT: '',
PAUSE: '',
ESCAPE: '',
SPACE: '',
PAGEUP: '',
PAGEDOWN: '',
END: '',
HOME: '',
LEFT_ARROW: '',
UP_ARROW: '',
RIGHT_ARROW: '',
DOWN_ARROW: '',
ARROW_LEFT: '',
ARROW_UP: '',
ARROW_RIGHT: '',
ARROW_DOWN: '',
INSERT: '',
DELETE: '',
SEMICOLON: '',
EQUALS: '',
NUMPAD0: '',
NUMPAD1: '',
NUMPAD2: '',
NUMPAD3: '',
NUMPAD4: '',
NUMPAD5: '',
NUMPAD6: '',
NUMPAD7: '',
NUMPAD8: '',
NUMPAD9: '',
MULTIPLY: '',
ADD: '',
SEPARATOR: '',
SUBTRACT: '',
DECIMAL: '',
DIVIDE: '',
F1: '',
F2: '',
F3: '',
F4: '',
F5: '',
F6: '',
F7: '',
F8: '',
F9: '',
F10: '',
F11: '',
F12: '',
COMMAND: '',
META: ''
},

You can press any key in above array easily like "client.keys(client.Keys.ENTER);".

Ashish Jain

unread,
Jul 27, 2016, 4:33:32 AM7/27/16
to NightwatchJs
You can try following way to press any key in nightwatch.js, i am pressing T and it is working superb!!

    client.keys("t", function(done) {
        client.pause(5000);
        client.expect.element('#carousel_container').to.have.css('display').which.equals('block');
    });

Paul Levesque

unread,
Aug 1, 2016, 12:10:50 PM8/1/16
to NightwatchJs
Try one of these:

this.setValue('@enter_path', this.api.Keys.ENTER); // on a selector

this.api.Keys.ENTER; // without selector

Thanks

Aravindhan S

unread,
Aug 2, 2016, 1:51:41 AM8/2/16
to NightwatchJs
Thanks Guys ! Looks like this can be achieved in different ways.

I added the below line on my code wherever I require key press,

.keys('\uE007') //To press Enter key.


The above documentation has special key codes for all keys.

On Tuesday, May 24, 2016 at 3:52:55 PM UTC+5:30, Aravindhan S wrote:

Aravindhan S

unread,
Aug 2, 2016, 1:57:03 AM8/2/16
to NightwatchJs
Credits to Bartosz Cholewiński <bartoszch...@gmail.com>, he suggested this solution but unfortunately his post has been deleted from this thread so I am reposting his answer.


On Tuesday, May 24, 2016 at 3:52:55 PM UTC+5:30, Aravindhan S wrote:

Lukáš Dziadkowiec

unread,
Feb 17, 2017, 8:12:12 AM2/17/17
to NightwatchJs
Any idea how to press a SHIFT + TAB simultaneously ? Thanks.

Eric Mumford

unread,
Feb 17, 2017, 2:42:29 PM2/17/17
to nightw...@googlegroups.com
Here is how you answer your own question,


1. Google 'selenium chord'
2. Read about using setValue and an array of KEY objects  https://github.com/nightwatchjs/nightwatch/issues/522



Happy fishing


On Fri, Feb 17, 2017 at 8:12 AM, Lukáš Dziadkowiec <i.f...@gmail.com> wrote:
Any idea how to press a SHIFT + TAB simultaneously ? Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "NightwatchJs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nightwatchjs/aIY704YizWc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nightwatchjs+unsubscribe@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/64c11bc4-f9fe-45d6-a3d5-bdbeb91aee42%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sailesh Botcha

unread,
Dec 14, 2017, 12:10:15 PM12/14/17
to NightwatchJs
How Can we Open A new Tab using nightwatchjs i have tried 

client.keys(client.Keys.CONTROL,"T"

but this doesn't work. 



On Saturday, February 18, 2017 at 1:12:29 AM UTC+5:30, Eric Mumford wrote:
Here is how you answer your own question,


1. Google 'selenium chord'
2. Read about using setValue and an array of KEY objects  https://github.com/nightwatchjs/nightwatch/issues/522



Happy fishing

On Fri, Feb 17, 2017 at 8:12 AM, Lukáš Dziadkowiec <i.f...@gmail.com> wrote:
Any idea how to press a SHIFT + TAB simultaneously ? Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "NightwatchJs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nightwatchjs/aIY704YizWc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nightwatchjs...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

Xianpeng Shen

unread,
Jan 2, 2018, 11:22:16 PM1/2/18
to NightwatchJs
Thank you very much, it works for me.

在 2016年8月2日星期二 UTC+8上午12:10:50,Paul Levesque写道:

Kiran Ranganathan

unread,
May 5, 2018, 1:04:20 PM5/5/18
to NightwatchJs
Thanks Aravindan, your method worked for me too in Nightwatch.

Lola Yan

unread,
May 30, 2018, 7:04:24 AM5/30/18
to NightwatchJs
This is working for me in Nightwatch Package Object, Thanks!!
Reply all
Reply to author
Forward
0 new messages