0
votes

As I know, selenium keyDown(keyUp) method is only available for keys in modifiers (SHIFT, ALT, CTRL). I need to press SPACE key a certain amount of time.

I have a questions about key event handling in Selenium keyboard interface.

1. Why selenium does not permit keydown and keyup event for other general keys ?

2. Is there any workaround to achieve this goal ?

For now, I used Robot class to implement this, but I don't want to use this.

1

1 Answers

0
votes

since you didn't tell us which Selenium-binding you are using, I will show my examples in Java, you may transcode them into any binding you please:

you can press the SPACE key via the sendKeys() method:

driver.sendKeys(Keys.SPACE);

I don't know why you would want to use the keyDown() keyUp() methods for the "general keys" you are talking about, you can also use sendKeys() for most objectives:

driver.sendKeys("a");

You can use the Actions class if you want to combine normal key-actions with keyDown()/keyUp() actions

Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).sendKeys("c").keyUp(Keys.CONTROL).perform(); 

for example to copy something via CTRL+c...