问题
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