How to deliver a click using modifier keys through Selenium WebDriver?

I have this line of code:

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

Now, how do I click on this button with the meta key pressed?

+5
source share
3 answers

According to Madd0g, Java code would look like this:

  Actions shiftClick = new Actions(driver);
  shiftClick.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).perform();
+8
source

hmm .. I'm not quite sure about java, but in C # this is done using ActionBuilder -

new Actions(Browser).KeyDown(Keys.Shift).Click(element).KeyUp(Keys.Shift).Perform(); 
+10
source

Found. http://code.google.com/p/selenium/wiki/AdvancedUserInteractions .

 final WebElement button = driver.findElement(By.id("button"));
    Actions actions = new Actions(driver);
    if (ctrlKey) {
        actions = actions.keyDown(Keys.CONTROL);
    }
    if (altKey) {
        actions = actions.keyDown(Keys.ALT);
    }
    if (shiftKey) {
        actions = actions.keyDown(Keys.SHIFT);
    }
    actions = actions.click(button);

Now, if only it really worked.

+2
source

All Articles