How to paste using the keys command in nightwatch?

浪子不回头ぞ 提交于 2019-12-23 09:15:38

问题


How can I paste in nightwatch? I tried this command:

browser.keys([browser.Keys.COMMAND, browser.Keys.v])

But the command is not working.

Ideally I would lake to be able to save the copied text into a variable.


回答1:


I had to add the third NULL parameter to all commands, not only the last one, then it worked. Sadly, I can't find any documentation about how this exactly works.

My usecase was selecting everything on a page with an image on it (ctrl+a), copying it (ctrl+v) and then navigating to another page with a CKeditor on it. Focussing on the ckeditor and pasting (ctrl+v) the image.

.keys([browser.Keys.CONTROL, 'a', browser.Keys.NULL])
.keys([browser.Keys.CONTROL, 'c', browser.Keys.NULL])
.keys([browser.Keys.CONTROL, 'v', browser.Keys.NULL])



回答2:


This is working for me, try this:

browser.keys([browser.Keys.CONTROL, "a"]) // highlight text
browser.keys([browser.Keys.CONTROL, "c"]) // copy text
browser.keys([browser.Keys.CONTROL, "v"]) // paste text



回答3:


The below command worked for me to hit ENTER KEY .

browser.keys([browser.Keys.ENTER]);


来源:https://stackoverflow.com/questions/31796607/how-to-paste-using-the-keys-command-in-nightwatch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!