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

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

Introduction

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

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

From source file:com.sugarcrm.candybean.automation.webdriver.WebDriverElement.java

License:Open Source License

/**
 * Drag this element and drop onto another element.
 * /* www  .  j  ava  2  s .c om*/
 * @param dropControl
 *            target of the drag and drop
 */
public void dragNDrop(WebDriverElement dropControl) throws CandybeanException {
    logger.info("Dragging element: " + this.toString() + " to element: " + dropControl.toString());
    Actions action = new Actions(this.wd);
    action.dragAndDrop(this.we, dropControl.we).build().perform();
}

From source file:com.sugarcrm.candybean.automation.webdriver.WebDriverElement.java

License:Open Source License

/**
 * Hover over this element./*from   w  ww . j a  v  a2  s .com*/
 */
public void hover() throws CandybeanException {
    logger.info("Hovering over element: " + this.toString());
    Actions action = new Actions(this.wd);
    action.moveToElement(this.we).perform();
}

From source file:com.sugarcrm.candybean.automation.webdriver.WebDriverElement.java

License:Open Source License

/**
 * Right-click this element./*from   ww  w. j av  a2  s .c  o  m*/
 */
public void rightClick() throws CandybeanException {
    logger.info("Right-clicking element: " + this.toString());
    Actions action = new Actions(this.wd);
    action.contextClick(this.we).perform();
}

From source file:com.tascape.qa.th.webui.comm.WebBrowser.java

License:Apache License

protected void setDefaults() {
    this.actions = new Actions(this.webDriver);
    this.webDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    this.webDriver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
    this.webDriver.manage().timeouts().setScriptTimeout(120, TimeUnit.SECONDS);
    this.hide();/* w  w  w  .  java  2  s. c o m*/
}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Performs a double click on the current element (set with a previous Find
 * method).//from  www  .java 2 s  . com
 * 
 * @example PerformDoubleClick
 * @section Clicks
 * 
 */
@Step("PerformDoubleClick")
public void doDoubleClick() {

    final Actions actions = new Actions(webDriver());

    actions.doubleClick(webDriverContext().getCurrentElement());

    actions.perform();
}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Performs a context click (typically right click, unless this has been
 * changed by the user) on the current element.
 * // w w  w .  j  a  v a 2  s  .  c o m
 * @example PerformContextClick
 * @section Clicks
 * 
 */
@Step("PerformContextClick")
public void performContextClick() {

    final Actions actions = new Actions(webDriver());

    actions.contextClick(webDriverContext().getCurrentElement());

    actions.perform();
}

From source file:com.testmax.handler.ElementHandler.java

License:CDDL license

protected String executeMove(String tag, String havintattribute) {
    WebElement elm = null;/*from   w w w . j  a  va2s  . com*/
    String id = "testmax_elm_move_id";
    HashMap<String, String> attribs = getAttributesList(tag, havintattribute);

    String txtcond = "elms[i].innerHTML && elms[i].innerHTML.indexOf(\"@text\")>=0 "
            + "||elms[i].innerText &&elms[i].innerText.indexOf(\"@text\")>=0"
            + "||elms[i].textContent &&elms[i].textContent.indexOf(\"@text\")>=0";
    String ifer = "";
    String setid = "";
    //if(this.operation.equalsIgnoreCase("write")||this.operation.equalsIgnoreCase("click")){
    setid = "\n\t\t\tif(elms[i].offsetWidth > 0 || elms[i].offsetHeight > 0)" + "\n\t\t\t\t{ "
            + "\n\t\t\t\t\telms[i].setAttribute('id','" + id + "');" + "\n\t\t\t\t\tbreak;" + "\n\t\t\t\t}";
    /* }else{
        setid= "\n\t\t\t"+
           "\n\t\t\t\telms[i].setAttribute('id','"+id+"');"+
           "\n\t\t\t\tbreak;"+
           "\n\t\t\t";
     }*/
    String script = "\n\tvar elms=null;" + "\n\t elms=document.querySelectorAll('" + tag + "'); "
            + "\n\tif(elms &&elms.length==1)\n\t\t\t\t{ " + "\n\t\t\t\t\telms[0].setAttribute('id','" + id
            + "');" +
            //"\n\t\t\t\t\t return;"+
            "\n\t\t\t\t}" + "\n\t\tfor (var i=0; i < elms.length; i++){" + "\n\t\t\tif( @cond)" + "\n\t\t\t\t{ "
            + setid + "\n\t\t\t\t}" + "\n\t\t}";

    String othercond = "";
    String textcondfinal = "";
    String amph = "";
    for (String key : attribs.keySet()) {
        key = key.trim();
        if (key.equalsIgnoreCase("id") && !this.isEmptyValue(attribs.get("id"))) {
            id = attribs.get("id");
            //elm=this.getDriver().findElement(By.id(id));
            elm = this.waitForElement(this.getDriver().findElement(By.id(id)), new Integer(500));
            break;
        }
        if (key.equalsIgnoreCase("text") && attribs.get(key) != null) {
            txtcond = txtcond.replaceAll("@text", attribs.get(key));
            if (attribs.size() > 1) {
                textcondfinal = "(" + txtcond + ")";
            } else {
                textcondfinal = txtcond;
            }
        }
        if ((key.equalsIgnoreCase("href") || key.equalsIgnoreCase("img")) && attribs.get(key) != null) {

            othercond += "&& elms[i].getAttribute('" + key.trim() + "').indexOf('" + attribs.get(key).trim()
                    + "')>=0";
        } else if (!key.equalsIgnoreCase("text") && !key.equalsIgnoreCase("xpath")
                && attribs.get(key) != null) {

            othercond += "&& elms[i].getAttribute('" + key.trim() + "')=='" + attribs.get(key).trim() + "'";
        }
    }
    if (elm == null) {

        try {
            textcondfinal = textcondfinal
                    + (this.isEmptyValue(textcondfinal) ? othercond.substring(2) : othercond);
            script = script.replace("@cond", textcondfinal);

            Thread.sleep(new Integer(500));
            ((JavascriptExecutor) this.getDriver()).executeScript(script);
            try {
                elm = this.waitForElement(this.getDriver().findElement(By.id(id)), new Integer(timeout));
            } catch (Exception e) {
                this.printMessage("####### Exception thrown while accesing Elementat getElementId() : "
                        + getExceptionMessage(e) + " Script=" + script);
                return id;
            }

        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            printMessage("**** Executed Java Script With EXCEPTION " + timer.getPrintTime() + " "
                    + getExceptionMessage(e) + " Script=" + script);
            return id;
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            printMessage("**** Executed Java Script With EXCEPTION " + timer.getPrintTime() + " "
                    + getExceptionMessage(e) + " Script=" + script);
            return id;
        } catch (WebDriverException e) {
            printMessage("**** Executed Java Script With EXCEPTION " + timer.getPrintTime() + " "
                    + getExceptionMessage(e) + " Script=" + script);
            return id;
        } catch (Exception e) {
            this.printMessage("####### Exception thrown while accesing Elementat getElementId() : "
                    + getExceptionMessage(e) + " Script=" + script);
            return id;
        }
        printMessage("**** Executed Java Script " + timer.getPrintTime() + " Script=" + script);
    }
    if (elm != null) {
        try {
            new Actions(this.getDriver()).moveToElement(elm).click().build().perform();

        } catch (Exception e) {
            this.printMessage("####### Exception thrown while click and movemouse : " + getExceptionMessage(e));
            return id;
        }

    }
    return id;
}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

protected boolean executeOperation() throws TestMaxException {
    PrintTime timer = new PrintTime();
    String elmId = "";
    WebElement elm = null;//from  w  w  w.  j  a v a 2  s.co  m

    if (this.isEmptyValue(this.tagName) && !this.isEmptyValue(this.havingTag)) {
        this.tagName = this.havingTag;
    }

    if (this.operation.equalsIgnoreCase("acceptalert")) {
        this.setImpilicitTimeInMiliSec(new Integer(timeout));
        this.getDriver().switchTo().alert().accept();
        this.printMessage("Invoked Custom Operation=" + this.operation);
        return true;
    } else if (this.operation.equalsIgnoreCase("runscript")) {
        this.setImpilicitTimeInMiliSec(new Integer(timeout));
        try {
            Thread.sleep(100);
            this.executeScript();
            this.printCommand(this.tagdesc + " for control with identifier=" + this.controlIdentifier
                    + "\n Script=" + addMessage());
            printMessage("**** Executed Java Script= " + addMessage() + " for Control=" + this.controlIdentifier
                    + ":" + addMessage());
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    } else if (this.operation.equalsIgnoreCase("closepopup")) {
        this.getElementByJavaScript();
        return true;
    }

    if (this.havingAttribute != null && !this.havingAttribute.isEmpty()) {
        //first check if element present
        this.controlIdentifier = " tagname=" + this.tagName + " and havingAttribute" + "="
                + this.havingAttribute;

        elm = getElementByTechnique();

        //log element to re-record
        elementToReRecord(elm);

        //if(this.isCustomOperation() ){
        try {

            if (this.operation.equalsIgnoreCase("read")) {

                this.readElement(elm);
                if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                    resetElementId(id);
                }

                return true;
            } else if (this.operation.equalsIgnoreCase("write")) {

                if (elm != null) {
                    try {
                        this.setImpilicitTimeInMiliSec(new Integer(timeout));
                        // this.waitForElement(this.getDriver().findElement(by), new Integer(timeout));
                        elm.sendKeys(this.sendkeyValue);
                        if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                            resetElementId(id);
                        }
                    } catch (Exception e) {
                        if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                            resetElementId(id);
                        }
                    }
                }
                //resetElementId();
                return true;

            } else if (this.operation.equalsIgnoreCase("click")) {
                //waitToPageLoad(new Integer(timeout));

                if (elm != null) {
                    try {
                        this.setImpilicitTimeInMiliSec(new Integer(timeout));

                        new Actions(this.getDriver()).moveToElement(elm).click().build().perform();
                        //this.mouseMove(elm);
                        String menuclick = ConfigLoader.getConfig("MENU_CLICK_NUMBER");
                        if (menuclick == null || !menuclick.equals("1")) {
                            try {
                                if (this.v_driver.equalsIgnoreCase("firefox") && elm.isDisplayed()) {
                                    Thread.sleep(500);
                                    elm = this.getDriver().findElement(By.id(elmId));
                                    new Actions(this.getDriver()).moveToElement(elm).click().build().perform();
                                    //this.mouseMove(elm);
                                }
                            } catch (Exception e) {
                                if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                                    resetElementId(id);
                                }
                            }
                        }
                        waitToPageLoad(new Integer(timeout));

                        if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                            resetElementId(id);
                        }
                        return true;
                    } catch (Exception e) {
                        if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                            resetElementId(id);
                        }
                    }
                }

            }

        } catch (Exception e) {
            if (!this.isEmptyValue(id) && id.equalsIgnoreCase("testmax_elm_lookup_id")) {
                resetElementId(id);
            }

            printMessage("**** Failed to Execute Java Script " + timer.getPrintTime() + " Element id=" + this.id
                    + " " + getExceptionMessage(e));
            return false;
        }
    }
    if (this.havingAttribute == null || this.havingAttribute.isEmpty()) {
        throw new TestMaxException(
                "$$$$$$ERROR: Operation can not be executed since havingAttribute property for tag Element is Empty!! Please modify your XML configuration in Taglib.");
    }

    return false;
}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

protected void uploadFile(WebElement elm) {
    Actions builder = new Actions(driver);

    Action myAction = builder.click(elm).release().build();

    myAction.perform();// w  w  w  . java  2 s. c o m

    Robot robot;
    try {
        robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.thoughtworks.selenium.webdriven.commands.ClickAt.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    WebElement element = finder.findElement(driver, locator);
    String[] parts = value.split(",");
    int xOffset = Integer.parseInt(parts[0]);
    int yOffset = Integer.parseInt(parts[1]);
    new Actions(driver).moveToElement(element, xOffset, yOffset).click().perform();
    return null;/* w  w  w  .j a  va  2 s .co  m*/
}