Example usage for org.openqa.selenium.interactions Actions doubleClick

List of usage examples for org.openqa.selenium.interactions Actions doubleClick

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions doubleClick.

Prototype

public Actions doubleClick() 

Source Link

Document

Performs a double-click at the current mouse location.

Usage

From source file:com.ggasoftware.jdi_ui_tests.elements.base.Element.java

License:Open Source License

public void doubleClick() {
    doJAction("Couble click on element", () -> {
        getWebElement().getSize(); //for scroll to object
        Actions builder = new Actions(getDriver());
        builder.doubleClick();
    });/*from w  w w  .ja  va2 s. co m*/
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Performs a double-click at the current mouse location.
 *
 * @return Parent instance//from ww  w.  ja  v a 2s.c  o m
 */
public ParentPanel doubleClick() {
    getWebElement().getSize(); //for scroll to object
    logAction(this, getParentClassName(), "doubleClick");
    alwaysDoneAction(() -> {
        Actions builder = new Actions(getDriver());
        builder.doubleClick();
    });
    return parent;
}

From source file:com.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

@Override
public void doubleClick(int numRetries) {
    try {//  ww w  .j  a va 2s.  c o m
        for (int i = 0; i < 5; i++) {
            try {
                WebElement webElem = findElement(numRetries);
                webElem.click();

                Actions webActions = new Actions(browser.getSeleniumWebDriver());
                webActions.doubleClick().build().perform();
                break;
            } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
                browser.waitForSeconds(2);
            }
        }
    } catch (Throwable th) {
        Assert.fail("Failed to perform mouse double click on element '" + domObject.getDisplayName() + "'.",
                th);
    }
}

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public void doubleClickAt(String locator, String coordString) {
    WebElement webElement = getWebElement(locator);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    if (Validator.isNotNull(coordString) && coordString.contains(",")) {
        String[] coords = coordString.split(",");

        int x = GetterUtil.getInteger(coords[0]);
        int y = GetterUtil.getInteger(coords[1]);

        actions.moveToElement(webElement, x, y);

        actions.doubleClick();
    } else {// w w  w . j  av  a2  s  .  c  o m
        actions.doubleClick(webElement);
    }

    Action action = actions.build();

    action.perform();
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

License:Open Source License

/**
 * Double-Click the WebElement at a certain coordination with a special key pressed.<br>
 * Firstly it will try to get webelement's location and use Robot to double click. At the same<br>
 * time, it will listen to a 'javascript mouse down' event to find out if the double click really<br>
 * happened; If not, it will try to use Selenium's API to do the work.<br>
 * If the click point is outside of the boundary of the WebElement, which means we are going<br>
 * to click on the sibling component. At this situation, our click-listener will never receive<br>
 * the click event, we will turn off the click-listener.<br>
 *
 * @param clickable    WebElement, the WebElement to click on
 * @param offset      Point, the coordination relative to this WebElement to click at.<br>
 *                         if the offset is null, then click at the center.
 * @param specialKey   Keys, the special key to press during the click
 * @param mouseButtonNumber int, the mouse-button-number representing right, middle, or left button.
 *                          it can be {@link #MOUSE_BUTTON_LEFT}<br>
 *                          {@link #MOUSE_BUTTON_MIDDLE} and {@link #MOUSE_BUTTON_RIGHT} NOT supported yet.
 * @param optional String[], the optional parameters
 * <ul>//from   ww  w  .j a  va 2  s.c  om
 * <li> optional[0] autoscroll boolean, if the component will be scrolled into view automatically before clicking.
 *                                      if not provided, the default value is true.
 * </ul>
 * @throws SeleniumPlusException
 */
public static void doubleClick(WebElement clickable, Point offset, Keys specialKey, int mouseButtonNumber,
        String... optional) throws SeleniumPlusException {
    String debugmsg = StringUtils.debugmsg(WDLibrary.class, "doubleClick");

    checkBeforeOperation(clickable, true);

    MouseEvent event = null;
    DocumentClickCapture listener = new DocumentClickCapture(true, clickable);
    checkOffset(clickable, offset, listener);
    boolean autoscroll = parseAutoScroll(optional);

    try {
        //2. Perform the click action by Robot
        Point location = getScreenLocation(clickable);
        if (offset != null)
            location.translate(offset.x, offset.y);
        else
            location.translate(clickable.getSize().width / 2, clickable.getSize().height / 2);
        listener.addListeners(false);
        RBT.click(location, specialKey, mouseButtonNumber, 2);
        listener.startListening();

        //3. Wait for the 'click' event, check if the 'mousedown' event really happened.
        event = listener.waitForClick(timeoutWaitClick);
        if (event == null) {
            IndependantLog.warn(
                    debugmsg + " Robot may fail to perform doubleclick. Click screen location is " + location);
            throw new SeleniumPlusException("The doubleclick action didn't happen.");
        } else {
            IndependantLog.debug(debugmsg + "doubleclick has been peformed.");
        }
    } catch (Throwable thr) {
        IndependantLog.warn(debugmsg + "Met Exception " + StringUtils.debugmsg(thr));
        try {
            //2. Perform the click action by Selenium
            IndependantLog.debug(debugmsg + " Try selenium API to doubleclick.");
            //Create a combined actions according to the parameters
            Actions actions = new Actions(WDLibrary.getWebDriver());

            if (autoscroll) {
                if (offset != null)
                    actions.moveToElement(clickable, offset.x, offset.y);
                else
                    actions.moveToElement(clickable);
            }

            if (specialKey != null)
                actions.keyDown(specialKey);
            if (isLeftMouseButton(mouseButtonNumber))
                actions.doubleClick();
            else if (isMiddleMouseButton(mouseButtonNumber) || isRightMouseButton(mouseButtonNumber)) {
                throw new SeleniumPlusException(
                        "Double click 'mouse middle/right button' has not been supported yet.");
            } else
                throw new SeleniumPlusException(
                        "Mouse button number '" + mouseButtonNumber + "' cannot be recognized.");

            if (specialKey != null)
                actions.keyUp(specialKey);

            IndependantLog.debug(debugmsg + "doubleclick with key '" + specialKey + "', mousebutton='"
                    + mouseButtonNumber + "'");

            //Perform the actions
            listener.addListeners(false);
            try {
                //unfortunately, if the Robot click worked, but was not detected, we have to wait the full
                //WebDriver implied timeout period for the perform() failure to occur.
                actions.build().perform();
                listener.startListening();
                event = listener.waitForClick(timeoutWaitClick);
                if (event != null)
                    IndependantLog.debug(debugmsg + "doubleclick has been peformed.");
                else {
                    throw new SeleniumPlusException(
                            "Selenium Action.doubleclick failed to detect the MouseEvent.");
                }
            } catch (StaleElementReferenceException x) {
                // the click probably was successful because the elements have changed!
                IndependantLog.debug(debugmsg
                        + "StaleElementException (not found) suggests the click has been performed successfully.");
            }
        } catch (Throwable th) {
            IndependantLog.error(debugmsg, th);
            throw new SeleniumPlusException("doubleclick action failed: " + StringUtils.debugmsg(th));
        }
    } finally {
        listener.stopListening();
    }
}

From source file:server.system.scripts.ImportLicense.java

public boolean importLicence(WebDriver objWebDriver, String licFilePath, Logger accessLog)
        throws InterruptedException, IOException {
    boolean result = false;

    // Navigate to Licenses tab:
    try {/*w  w  w .  j a  v a  2s  .c  om*/
        CommonFunctions.navigateToTab(MenuNavigation.ImportLicense, objWebDriver, accessLog, null);
        // Check if the license is already imported or not, if not - import
        // the license:
        if (!objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                .getAttribute("title").toString().equalsIgnoreCase("License Active")) // Status
        // strings
        // for
        // validation
        // -
        // 'No
        // License'
        // 'License
        // Active'
        {
            // Click on Import License
            CommonFunctions.doClickAndSwitchToIFrame(objWebDriver, accessLog,
                    By.xpath(MenuNavigation.System.ImportLicense.btnImportLicense),
                    By.id(MenuNavigation.System.ImportLicense.frmIDImportLicense));
            Thread.sleep(2000);

            // find and Click on Browse button
            WebElement btnBrowse = objWebDriver
                    .findElement(By.xpath(MenuNavigation.System.ImportLicense.btnBrowse));
            Actions builder = new Actions(objWebDriver);
            builder.moveToElement(btnBrowse).perform();
            builder.doubleClick().perform();

            // Call AutoIT exe
            String[] commands = { Driver.mConfigFile.getLibFolder() + File.separator + "import_license.exe",
                    "Choose File to Upload", licFilePath };

            try {
                Process proc;
                proc = Runtime.getRuntime().exec(commands);
                // Wait for AutoIT script to end successfully
                InputStream is = proc.getInputStream();
                int retCode = 0;
                while (retCode != -1) {
                    retCode = is.read();
                    blnStatus = true;
                }
                is.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                accessLog.error("Caught exception while executing the AutoIT script");
                e1.printStackTrace();
                result = false;
            }

            // Click on Import button
            CommonFunctions.doClickAndWait(objWebDriver,
                    By.xpath(MenuNavigation.System.ImportLicense.btnImport),
                    By.xpath(MenuNavigation.System.ImportLicense.btnImportLicense), accessLog);
            Thread.sleep(1000);

            // Take screen shot
            if (blnStatus) {
                // validate that license has been imported successfully
                if (objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                        .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")) {
                    accessLog.info(
                            "The license file : has been imported successfully and below are the details about active license");
                    accessLog
                            .info("Windows Server : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedWS))
                                            .getText().toString());
                    accessLog
                            .info("Windows WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedWW))
                                            .getText().toString());
                    accessLog
                            .info("Linux Server : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedLS))
                                            .getText().toString());
                    accessLog
                            .info("Linux WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedLW))
                                            .getText().toString());
                    accessLog
                            .info("MAC WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedMW))
                                            .getText().toString());

                }
                // Take Screenshot
                CommonFunctions.takeScreenshot(objWebDriver, strCurScriptName, "license_imported", accessLog);
                result = true;
            }
        } else if (objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                .getAttribute("title").toString().equalsIgnoreCase("License Active")) {
            accessLog.info("the license is already imported, here is the summary :: ");
            accessLog.info("Windows Server : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedWS))
                            .getText().toString());
            accessLog.info("Windows WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedWW))
                            .getText().toString());
            accessLog.info("Linux Server : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedLS))
                            .getText().toString());
            accessLog.info("Linux WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedLW))
                            .getText().toString());
            accessLog.info("MAC WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedMW))
                            .getText().toString());
            result = true;
        }
    } catch (Exception e) {
        accessLog.error("Caught Exception while Importing the license ");
        accessLog.error(e.getMessage());
        e.printStackTrace();
        result = false;
    }
    return result;
}