I met a problem that selenium cannot press and hold a key that is not in this list -
Keys.SHIFT,
Keys.CONTROL,
Keys.ALT,
Keys.META,
Keys.COMMAND,
Keys.LEFT_ALT,
Keys.LEFT_CONTROL,
Keys.LEFT_SHIFT
My application shows instructions only when you press and hold the spacebar. I want to write browser tests for this.
I use ProtractorJS, but it seems to be a common limitation for such an action, everywhere in selenium, when you try to use keyDown for another key - you will get an exception from this message: "Key Down / Up events make sense for modifier keys."
here is the link to Selenium Java code:
https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/interactions/internal/SingleKeyAction.java#L48
selenium js:
https://github.com/SeleniumHQ/selenium/blob/master/javascript/webdriver/actionsequence.js#L301
? .
UPDATE:
Florent B. .
- . .
browser.switchTo().frame('workspace');
const SIMULATE_KEY =
"var e = new Event('keydown');" +
"e.keyCode = 32;" +
"e.which = e.keyCode;" +
"e.altKey = false;" +
"e.ctrlKey = false;" +
"e.shiftKey = false;" +
"e.metaKey = false;" +
"e.bubbles = true;" +
"document.dispatchEvent(e);";
browser.executeScript(SIMULATE_KEY);