Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deliver a click with modifier keys via Selenium's WebDriver?

Tags:

selenium

I've got this line of code:

final WebElement button = driver.findElement(By.tagName("button"));

Now, how to I click on that button with the meta key held down?

like image 885
bmargulies Avatar asked Dec 18 '11 15:12

bmargulies


2 Answers

As per Madd0g, java code would look like this:

  Actions shiftClick = new Actions(driver);
  shiftClick.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).perform();
like image 67
Goran Vasic Avatar answered Oct 01 '22 18:10

Goran Vasic


hmm.. I'm not exactly sure about java, but in C# this is done with the ActionBuilder --

new Actions(Browser).KeyDown(Keys.Shift).Click(element).KeyUp(Keys.Shift).Perform(); 
like image 28
Madd0g Avatar answered Oct 01 '22 19:10

Madd0g