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

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

Introduction

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

Prototype

public Actions click(WebElement target) 

Source Link

Document

Clicks in the middle of the given element.

Usage

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  ww. ja  v  a  2s  .  c o m
 */
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   ww w . ja  va 2  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.sios.stc.coseng.test.User.java

License:Open Source License

@Test(description = "Verify bad credentials deny access past the login page", dataProvider = "credentials")
// @Parameters({ "x,x", "y,y" })
// public void aInvalidLogin(final String username, final String password)
public void invalidLogin(final String username, final String password) throws Exception {

    User.log.log(Level.INFO, logTestName() + " Username: " + username + " Password: " + password);

    driver.get(baseUrl + "/ui/#/login");
    acceptSslCertificate(driver);//from   w  w w .  j a v  a2 s  .  c om

    final WebDriverWait wait = new WebDriverWait(driver, 10);
    final Actions actions = new Actions(driver);

    final WebElement weUsername = driver.findElement(By.name("userName"));
    final WebElement wePassword = driver.findElement(By.name("password"));
    final WebElement weSubmit = driver.findElement(By.className("login_submit_button"));

    wait.until(ExpectedConditions.visibilityOf(weUsername));
    wait.until(ExpectedConditions.visibilityOf(wePassword));
    wait.until(ExpectedConditions.visibilityOf(weSubmit));

    saveScreenshot(driver, "aftervisible-" + username);

    actions.moveToElement(wePassword).click().sendKeys(wePassword, password).build().perform();
    actions.moveToElement(weUsername).click().sendKeys(weUsername, username).build().perform();
    actions.click(weSubmit).build().perform();

    final WebElement weDialogBox = driver.findElement(By.className("dialog_box"));
    final WebElement weDialogBtnOk = driver.findElement(By.className("dialog_button"));

    wait.until(ExpectedConditions.visibilityOf(weDialogBox));

    actions.click(weDialogBtnOk).build().perform();
}

From source file:com.sios.stc.coseng.test.User.java

License:Open Source License

@Test(description = "Verity initial login, change password.", dataProvider = "credentials")
public void firstLogin(final String username, final String password, final String newPassword)
        throws Exception {

    User.log.log(Level.INFO,//from  w w  w  .j  av  a  2s  .  c  o  m
            "Username: " + username + " Password: " + password + " NewPassword: " + newPassword);

    driver.get(baseUrl + "/ui/#/login");

    final WebDriverWait wait = new WebDriverWait(driver, 10);
    final Actions actions = new Actions(driver);

    WebElement weUsername = driver.findElement(By.name("userName"));
    WebElement wePassword = driver.findElement(By.name("password"));
    WebElement weSubmit = driver.findElement(By.className("login_submit_button"));

    actions.moveToElement(weUsername).sendKeys(weUsername, username).moveToElement(wePassword)
            .sendKeys(wePassword, password).click(weSubmit).build().perform();

    WebElement weNewPassword = driver.findElement(By.name("newpassword"));
    WebElement weRePassword = driver.findElement(By.name("repassword"));
    final WebElement weCancel = driver.findElement(By.linkText("Cancel"));

    wait.until(ExpectedConditions.visibilityOf(weNewPassword));

    actions.moveToElement(weNewPassword).sendKeys(weNewPassword, newPassword).build().perform();

    actions.moveToElement(weRePassword).sendKeys(weRePassword, newPassword).build().perform();

    actions.click(weCancel).build().perform();

    weUsername = driver.findElement(By.name("userName"));
    wePassword = driver.findElement(By.name("password"));
    weSubmit = driver.findElement(By.className("login_submit_button"));

    wait.until(ExpectedConditions.visibilityOf(weUsername));

    actions.moveToElement(weUsername).sendKeys(weUsername, username).moveToElement(wePassword)
            .sendKeys(wePassword, password).click(weSubmit).build().perform();

    weNewPassword = driver.findElement(By.name("newpassword"));
    weRePassword = driver.findElement(By.name("repassword"));
    final WebElement weOk = driver.findElement(By.linkText("OK"));

    wait.until(ExpectedConditions.visibilityOf(weNewPassword));

    actions.moveToElement(weNewPassword).sendKeys(weNewPassword, newPassword).moveToElement(weRePassword)
            .sendKeys(weRePassword, newPassword).click(weOk).build().perform();

    final WebElement weManageArea = driver.findElement(By.className("manage_area_2"));

    wait.until(ExpectedConditions.visibilityOf(weManageArea));

    Assert.assertTrue(weManageArea.isDisplayed());
}

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 .j  ava 2s  .c om*/

    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.vaadin.tests.components.draganddropwrapper.DragAndDropFocusObtainTest.java

License:Apache License

@Test
public void testTextAreaDndImage() {
    openTestURL();//from w w w  . j  a  v  a2  s .c  o m

    WebElement wrapper = driver.findElement(By.className("v-ddwrapper"));
    Actions actions = new Actions(driver);
    actions.click(wrapper);
    actions.perform();

    WebElement focusedElement = driver.findElement(By.className("v-textarea-focus"));
    Assert.assertNotNull("Text area did not obtain focus after click", focusedElement);

}

From source file:com.vaadin.v7.tests.components.grid.GridResizeHiddenColumnTest.java

License:Apache License

@Test
public void testDragResizeHiddenColumnSize() {
    GridElement grid = $(GridElement.class).first();
    Actions action = new Actions(getDriver());

    // Check if column 'Gender' hidden
    List<GridCellElement> headerCells = grid.getHeaderCells(0);
    Assert.assertEquals("There should be two visible columns", 2, headerCells.size());
    Assert.assertFalse("Gender column should be hidden", containsText("Gender", headerCells));

    // Resize first column
    int dragOffset = -100;
    int headerCellWidth = headerCells.get(0).getSize().getWidth();
    dragResizeColumn(headerCells.get(0), 1, dragOffset);

    // When dragging the resizer on IE8, the final offset will be smaller
    // (might be an issue with the feature that doesn't start resizing until
    // the cursor moved a few pixels)
    double delta = BrowserUtil.isIE8(getDesiredCapabilities()) ? 5d : 0;
    Assert.assertEquals("Column width should've changed by " + dragOffset + "px", headerCellWidth + dragOffset,
            headerCells.get(0).getSize().getWidth(), delta);

    // Make column 'Gender' visible
    WebElement menuButton = grid.findElement(By.className("v-contextmenu")).findElement(By.tagName("button"));
    action.click(menuButton).perform(); // Click on menu button

    WebElement sidebarPopup = findElement(By.className("v-grid-sidebar-popup"));
    WebElement visibilityToggle = findElementByText("Gender",
            sidebarPopup.findElements(By.className("gwt-MenuItem")));
    action.click(visibilityToggle).perform(); // Click on 'Gender' menu item

    // Check if column 'Gender' is visible
    headerCells = grid.getHeaderCells(0);
    Assert.assertEquals("There should be three visible columns", 3, headerCells.size());
    Assert.assertTrue("Gender column should be visible", containsText("Gender", headerCells));

    // Check if column 'Gender' has expanded width
    int widthSum = 0;
    for (GridCellElement e : headerCells) {
        widthSum += e.getSize().getWidth();
    }//from   w w  w .java  2s .  c  o m
    Assert.assertEquals("Gender column should take up the remaining space",
            grid.getHeader().getSize().getWidth(), widthSum, 1d);
}

From source file:com.zaizi.automation.alfresco.core.pages.AdminConsolePage.java

License:Open Source License

/**
 * Change System Theme/*  w w  w  .  j a v  a2  s .  c o  m*/
 * 
 * @param themeName
 *            : Name of the theme
 * @throws InterruptedException
 * @throws AWTException
 */

public void changeTheme(String themeName) throws InterruptedException, AWTException {
    NavigateToPage navigateToPage = new NavigateToPage(driver);
    navigateToPage.goToHome();
    Element.waitForLoad(driver);
    navigateToPage.goToAdminTools();
    Element.waitForLoad(driver);

    Actions action = new Actions(driver);

    Button themeDropDown = new Button(driver, By.xpath("//div//select[@id='console-options-theme-menu']"));
    themeDropDown.click();
    Thread.sleep(500);

    WebElement themeSelect = driver.findElement(By.xpath(
            "//div//select[@id='console-options-theme-menu']//option[contains(text(),'" + themeName + "')]"));

    action.click(themeSelect).sendKeys(Keys.ENTER).build().perform();
    Thread.sleep(1000);
    Element.waitForLoad(driver);
    Thread.sleep(1000);
    Button applyButton = new Button(driver,
            By.xpath("//div[@class='apply']//span//span//button[contains(text(),'Apply')]"));
    applyButton.click();
    Thread.sleep(1000);
    Element.waitForLoad(driver);
    Thread.sleep(500);
    navigateToPage.goToHome();
    Element.waitForLoad(driver);
}

From source file:contentspeed.ProdusCeai.java

void CosClick() {

    Actions actions = new Actions(driver);
    actions.click(driver.findElement(cosComanda)).perform();

}

From source file:contentspeededgedriver.ProdusCeai.java

void CosClick() {
    //driver.findElement(cosComanda).click();

    Actions actions = new Actions(driver);
    actions.click(driver.findElement(cosComanda)).perform();
    String MainWindow = driver.getWindowHandle();

    Set<String> s1 = driver.getWindowHandles();
    Iterator<String> i1 = s1.iterator();

    //System.out.println(s1.size());

    while (i1.hasNext()) {
        String ChildWindow = i1.next();

        driver.switchTo().window(ChildWindow);

        driver.findElement(By.partialLinkText("Vezi cosul")).click();

    }//  www. j a va  2 s .  c  o m
}