nightwatch.jsnightwatch

How to send keypress combinations in nightwatch


I can send a single key press in night-watch without a problem, but I need to press combination of them. For example UP_ARROW + SHIFT

Code from page objects.

this.sendKeys('@pmField', this.api.Keys.UP_ARROW+this.api.Keys.SHIFT)

This function just sends keys in a sequence. Firstly arrow up and then shift and I'm expecting that they would be pressed together as a combination.


Solution

  • browser
      .keys(browser.Keys.CONTROL) // hold the control
      .click('#element') // click something
      .keys(browser.Keys.NULL) // release the control
    

    This works properly in my tests when i need to click multiple elements while holding the control key. I think you can combine it with following key strokes instead of clicks. Hope this helps.