如何在守夜人中发送按键组合

How to send keypress combinations in nightwatch

我可以毫无问题地在夜间发送单个按键,但我需要按下它们的组合。例如UP_ARROW + SHIFT

来自页面对象的代码。

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

这个函数只是按顺序发送按键。首先向上箭头,然后移动,我希望它们会作为一个组合被压在一起。

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

当我需要在按住控制键的同时单击多个元素时,这在我的测试中正常工作。我认为您可以将它与以下击键而不是点击结合起来。希望这有帮助。

如 Skuubi80 所述,您可以使用 browser.keys()。

看看 api doc 并记下这一行...

Rather than the setValue, the modifiers are not released at the end of the call. The state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed.

请记住,这确实意味着您需要在完成后调用 browser.keys('null') 到 'un-press' 键。

希望对您有所帮助:)