How to keyPress + click with selenium How to keyPress + click with selenium selenium selenium

How to keyPress + click with selenium


This is a bug in Selenium, affecting shift/control/alt combined with clicks on Firefox for Windows. Star the bug and perhaps they will fix it.


I really have no idea why none of your attempts work (particularly the first one). The key constants are a mess.

Anyway, I have been able to make this work (on Windows XP):

Robot robot = new Robot();robot.keyPress(KeyEvent.VK_CONTROL);elements.get(0).click();elements.get(1).click();robot.keyRelease(KeyEvent.VK_CONTROL);


I think that`s not a bug.

Try use this (C#):

Action builder = new Actions(driver);builder.KeyDown(Keys.Control);builder.Click(element1);builder.Click(element2);builder.KeyUp(Keys.Control);builder.Perform();  

or for you(Java):

Actions a = new Actions(browser); a.keyDown(Keys.CONTROL) .moveToElement(elements.get(0)) .click() .moveToElement(elements.get(1)) .click() .keyUp(Keys.CONTROL) .build() .perform();

Just instead of

.Click(); .build(); .perform();

use

a.Click(YourWebElement);a.keyUp(Keys.CONTROL);a.build();a.perform();

Should works,