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.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * This method shall perform the MoveToElement wrap function of WebDriver.
 * We have to do this wrap to avoid StaleElement exceptions.
 * //from  www .  jav  a2s  .  c  o m
 * @param driver
 * @param toLocator
 */
public void MoveToElement(final WebDriver driver, final By toLocator) {
    this.log.debug("MoveToElement::Enter");
    try {
        WebElement element = FindElementInvisible(driver, toLocator);
        if (element != null) {
            Actions acts = new Actions(driver);
            acts.moveToElement(element);
            acts.build().perform();
        } else {
            this.log.warn("Element null!");
        }
    } catch (StaleElementReferenceException sere) {
        this.log.warn("Stale Element Reference Exception");
        MoveToElement(driver, toLocator);
    }
    this.log.debug("MoveToElement::Exit");
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * This method shall perform the MoveToElement wrap function of WebDriver.
 * We have to do this wrap to avoid StaleElement exceptions.
 * /*  w ww.java  2s .  co  m*/
 * @param driver
 * @param toLocator
 * @param xOffset
 * @param yOffset
 */
public void MoveToElement(final WebDriver driver, final By toLocator, final int xOffset, final int yOffset) {
    this.log.debug("MoveToElement::Enter");
    try {
        WebElement element = WaitForElementPresenceAndVisible(driver, toLocator);
        if (element != null) {
            Actions acts = new Actions(driver);
            acts.moveToElement(element, xOffset, yOffset);
            acts.build().perform();
        } else {
            this.log.warn("Element null!");
        }
    } catch (StaleElementReferenceException sere) {
        this.log.warn("Stale Element Reference Exception");
        MoveToElement(driver, toLocator, xOffset, yOffset);
    }
    this.log.debug("MoveToElement::Exit");
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * This method will empty a folder in the repository given the full path to it, including the folder name
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found. If it returns
 * true, all files shown on the files table will be selected, Delete button will be clicked on File Actions, it will
 * wait for popup and confirm the delete action.
 *
 * @param path//from  w w  w . j  av a 2s.c om
 */
public void EmptyFolder(String path) {
    if (SelectFolder(path)) {
        WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
        List<WebElement> AllFolderFiles = listFiles.findElements(By.xpath("//div[@class='title']"));

        // Check if the widget named exist
        if (AllFolderFiles != null) {
            if (AllFolderFiles.size() > 0) {
                WebElement[] arrayAllFolderFiles = new WebElement[AllFolderFiles.size()];
                AllFolderFiles.toArray(arrayAllFolderFiles);

                // Where we want to select three files
                // <the widget>
                // <the widget>.cdfde
                // <the widget>.component.xml
                // To do that we select each file (using the CONTROL key) and delete them.
                Actions action = new Actions(this.DRIVER);
                action.keyDown(Keys.CONTROL);
                for (WebElement arrayAllFolderFile : arrayAllFolderFiles) {
                    action.click(arrayAllFolderFile);
                }
                action.keyUp(Keys.CONTROL);
                action.build().perform();

                // Here we still in the iframe
                assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton")).click();
                // Go back to root html
                this.DRIVER.switchTo().defaultContent();
                assertEquals(this.elemHelper
                        .WaitForElementPresenceAndVisible(this.DRIVER, By.cssSelector("div.gwt-HTML"))
                        .getText(), "Are you sure you want to move all selected items to the trash?");
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                // wait for visibility of waiting pop-up
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='spinner large-spinner']"));
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("(//div[@class='spinner large-spinner'])[2]"));

            }
        }
    } else {
        LOG.info("folder not emptied for it was not found");
    }
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * Given the path to a folder this method will delete all files located in that folder that contain a specific string
 * in the name//from  w  w  w . j a  v a2  s  .c o  m
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found.
 *
 * If it returns true, all files containing string "name" provided in the name will be selected, Delete button will be
 * clicked on File Actions, it will wait for popup and confirm the delete action.
 *
 * @param path
 * @param name
 */
public void DeleteMultipleFilesByName(String path, String name) {
    LOG.debug("DeleteMultipleFilesByName::Enter");
    if (SelectFolder(path)) {
        LOG.debug("Deleting [" + path + "] with name [" + name + "]");

        WebElement elemWidgetFile = this.elemHelper.WaitForElementPresence(this.DRIVER,
                By.cssSelector("div[title='" + name + ".wcdf']"), 1);
        if (elemWidgetFile != null) {
            WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                    By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
            List<WebElement> theNamedFiles = listFiles
                    .findElements(By.xpath("//div[@class='title' and contains(text(),'" + name + "')]"));

            // Check if the widget named exist
            if (theNamedFiles != null) {
                if (theNamedFiles.size() > 0) {
                    WebElement[] arraytheNamedFiles = new WebElement[theNamedFiles.size()];
                    theNamedFiles.toArray(arraytheNamedFiles);

                    // Where we want to select three files
                    // <the widget>
                    // <the widget>.cdfde
                    // <the widget>.component.xml
                    // To do that we select each file (using the CONTROL key) and delete them.
                    Actions action = new Actions(this.DRIVER);
                    action.keyDown(Keys.CONTROL);
                    for (WebElement arraytheNamedFile : arraytheNamedFiles) {
                        action.click(arraytheNamedFile);
                    }
                    action.keyUp(Keys.CONTROL);
                    action.build().perform();

                    // Here we still in the iframe
                    assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton"))
                            .click();
                    // Go back to root html
                    this.DRIVER.switchTo().defaultContent();
                    assertEquals(
                            this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                                    By.cssSelector("div.gwt-HTML")).getText(),
                            "Are you sure you want to move all selected items to the trash?");
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                    // wait for visibility of waiting pop-up
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("applicationShell")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//iframe[@id='browser.perspective']")));
                    this.DRIVER.switchTo().frame("browser.perspective");

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("fileBrowser")));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    this.elemHelper.Click(this.DRIVER, By.id("refreshBrowserIcon"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    // Assert Panels
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFolders']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFiles']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserButtons']")));
                    LOG.info("Exit: Assert browser perspective shown");
                } else {
                    LOG.debug("No file exist!");
                }
            } else {
                LOG.debug("Null - No file exist!");
            }
        } else {
            LOG.warn("The widget does not exist.");
        }
    } else {
        LOG.info("Files were not deleted or folder was not found!");
    }
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseBaseTests.java

License:Open Source License

public void mouseReleaseById(String id) {
    verifyElementPresentById(id);// www . jav a 2s  . com
    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.id(id));
    action.moveToElement(we).release().perform();
    System.out.println("testing");
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseBaseTests.java

License:Open Source License

public void mouseClickAndHoldOverElementById(String id) {
    verifyElementPresentById(id);/*  w w  w. ja  v a  2s . c o  m*/
    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.id(id));
    action.moveToElement(we).clickAndHold().perform();
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseBaseTests.java

License:Open Source License

public void mouseOverElementByXpath(String xpath) {
    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.xpath(xpath));
    action.moveToElement(we).build().perform();
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseTests.java

License:Open Source License

protected void scrollbarVerticalDownScroll() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("javascript:window.scrollBy(250,700)");
    WebElement pickerScroll = driver.findElement(By.className("jspDrag"));
    WebElement pickerScrollCorner = driver.findElement(By.className("jspCorner"));
    Actions builder = new Actions(driver);
    // pickerscroll is the webelement
    Actions movePicker = builder.dragAndDrop(pickerScroll, pickerScrollCorner);
    movePicker.perform();/*  w  w w  . jav  a 2  s  .  c  o m*/
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseTests.java

License:Open Source License

protected void scrollbarHorizontalRightScroll() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("javascript:window.scrollBy(250,700)");
    WebElement pickerScroll = driver/*from  www .  ja  va  2  s . co m*/
            .findElement(By.xpath("//div[@id='gview_queryStatisticsList']/div[3]/div/div[3]/div[2]/div"));
    WebElement pickerScrollCorner = driver.findElement(By.className("jspCorner"));
    Actions builder = new Actions(driver);
    // pickerscroll is the webelement
    Actions movePicker = builder.dragAndDrop(pickerScroll, pickerScrollCorner);
    movePicker.perform();
}

From source file:com.pramati.wavemaker.pages.Deployment.java

License:Open Source License

public void navigateToNewUrl(String url) {
    driver.get(url);/*from  w  w  w .  ja va2 s .co  m*/
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {

    }
    Actions actions = new Actions(driver);
    actions.sendKeys(Keys.ENTER).build().perform();
}