1

help me please, i have a WebDriver script:

package AdvancedInteraction;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class ActionClick {
    public static void main(String[] args){
        WebDriver driver = new FirefoxDriver();
        driver.get("file:///C:/Selectable.html");
        WebElement one = driver.findElement(By.name("one"));
        WebElement three = driver.findElement(By.name("three"));
        WebElement five = driver.findElement(By.name("five"));
        // Add all the actions into the Actions builder.
        Actions builder = new Actions(driver);
        builder.keyDown(Keys.CONTROL)
        .click(one)
        .click(three)
        .click(five)
        .keyUp(Keys.CONTROL);
        // Generate the composite action.
        Action compositeAction = builder.build();
        // Perform the composite action.
        compositeAction.perform();
    }
}

but when i execute this script it doesn't click with CONTROL button. Why does it happen ?

1

It looks like this may be a bug with selenium - see https://code.google.com/p/selenium/issues/detail?id=3734.

There are some workarounds in that thread, but I would suggest to perhaps instead of building an action chain like this, specify the click method with a keydown modifier. So you can

Actions click1 = new Actions(driver);
click1.keyDown(Keys.CONTROL);
click1.click(one);
click.perform();

perhaps that may get around some of the issues you've been seeting.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.