Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29139

Webdriver: Send keys to canvas using JS

I have this canvas game which listens for key presses. Now I'm trying to use Selenium Webdriver to automate gameplay. However, when I try to send a key press to the canvas I get the following error:

Error: Not a modifier key

Here is the code:

browser.findElement(webdriver.By.css('#canvas')).then(function(result){
    var as = new webdriver.ActionSequence(browser);                                          
    as.keyUp(webdriver.Key.SPACE);
});

Any help would be appreciated ?

Upvotes: 1

Views: 788

Answers (1)

alecxe
alecxe

Reputation: 473893

Try with regular sendKeys():

as.sendKeys(webdriver.Key.SPACE);

Or, with keyDown() and then keyUp():

as.keyDown(webdriver.Key.SPACE).keyUp(webdriver.Key.SPACE);

Upvotes: 1

Related Questions