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

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

Introduction

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

Prototype

public Actions moveToElement(WebElement target) 

Source Link

Document

Moves the mouse to the middle of the element.

Usage

From source file:com.pentaho.ctools.cdf.require.CommentComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*  w  w w.  ja va  2  s. c  o  m*/
 *    Display Page
 * Description:
 *    We pretend validate to check if a comment is removed.
 * Steps:
 *    1. Add a comment
 *    2. Remove added comment
 */
@Test
public void tc5_RemoveComment_CommentRemoved() {
    this.log.info("tc5_RemoveComment_CommentRemoved");
    this.tcRemoveComment = true;
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String commentText = "Some comment!";
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(commentText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    //wait for the page rendered
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("div.navigateRefresh"));
    //Check if the comment was added
    String commentAdded = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded, commentText);

    /*
     * ## Step 2
     */
    Actions acts = new Actions(driver);
    acts.moveToElement(this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div")));
    acts.build().perform();
    acts.perform();
    acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.archive")));
    acts.click();
    acts.perform();
    //Check we don't have more comments
    noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String refreshComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.navigateRefresh"));
    assertEquals("Refresh", refreshComments);
}

From source file:com.pentaho.ctools.cdf.require.CommentComponent.java

License:Apache License

/**
 * This method shall clean all existence comments.
 *///from w  w w  .  ja  v a  2 s . com
private void cleanAllComments() {
    this.log.info("Remove comments");

    ElementHelper elemHelper = new ElementHelper();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    List<WebElement> listEraseComments = driver.findElements(By.cssSelector("div.archive"));
    int nIteractions = listEraseComments.size();
    this.log.info("Number elements to remove: " + nIteractions);
    if (nIteractions > 0) {
        this.log.debug("We have comments to remove");
        for (int i = 1; i <= nIteractions; i++) {
            Actions acts = new Actions(driver);
            acts.moveToElement(elemHelper.FindElement(driver,
                    By.xpath("//div[@id='sampleObject']/div/div/div/div[2]/div[2]")));
            acts.perform();
            acts.moveToElement(elemHelper.FindElement(driver,
                    By.xpath("//div[@id='sampleObject']/div/div/div/div[2]/div[2]/div")));
            acts.click();
            acts.perform();
            this.log.debug("One comment removed.");
        }
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.pentaho.ctools.cdf.require.JFreeChartComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://from w  w w.j  av  a  2s  .  c o m
 *    Select Month
 * Description:
 *    The test case pretends to validate an alert is displayed after select
 *    a month and the alert displayed the selected month.
 * Steps:
 *    1. Open Pie Chart
 *    2. Click on chart
 *    3. Open Bar Chart
 *    4. Click on chart
 */
@Test
public void tc3_ClickOnChart_AlertDisplayed() {
    this.log.info("tc3_ClickOnChart_AlertDisplayed");

    String title = "";
    String firstChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"), "src");

    /*
     * ## Step 1
     */
    ActionsHelper actsHelper = new ActionsHelper(driver);
    actsHelper.MouseOver(By.xpath("//div[contains(text(),'Details')]"));
    title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle"));
    assertTrue(title.equals("Top 10 Customers"));
    this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']"));
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Check if the generated image is different from previews, is not something static
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//img[@id='sampleObjectimage']")));
    String secondChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"),
            "src");
    assertNotEquals(firstChart, secondChart);

    /*
     * ## Step 2
     */
    //Click in 'Dragon Souveniers, Ltd.'
    this.elemHelper.Click(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[4]"));
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Dragon Souveniers, Ltd.", confirmationMsg);
    //Click in 'Mini Gifts Distributors Ltd'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[9]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Mini Gifts Distributors Ltd.", confirmationMsg);

    /*
     * ## Step 3
     */
    Actions acts2 = new Actions(driver);
    acts2.moveToElement(this.elemHelper.FindElement(driver, By.xpath("//div[contains(text(),'Details')]")));
    acts2.perform();
    //Open the Pie Chart
    title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle"));
    assertTrue(title.equals("Top 10 Customers"));
    this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']"));
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Check if the generated image is different from previews, is not something static
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//img[@id='sampleObjectimage']")));
    String thirdChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"), "src");
    assertNotEquals(firstChart, thirdChart);
    assertNotEquals(secondChart, thirdChart);

    /*
     * ## Step 4
     */
    //Click in 'Australian Collectors, Co.'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[8]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Australian Collectors, Co.", confirmationMsg);
    //Click in 'Down Under Souveniers, Inc'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[5]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Down Under Souveniers, Inc", confirmationMsg);
}

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

License:Apache License

/**
 * The function will search for the element present (doesn't matter
 * if element is visible or not) and then click on it.
 *
 * @param driver//from  w ww . j  a  v  a  2  s  .c  om
 * @param locator
 */
public void MoveToElementAndClick(WebDriver driver, By locator) {
    this.log.debug("MoveToElementAndClick::Enter");

    try {
        WebElement element = WaitForElementPresenceAndVisible(driver, locator);
        if (element != null) {
            Actions builder = new Actions(driver);
            builder.moveToElement(element).click(element);
            builder.perform();
        } else {
            this.log.error("Element is null " + locator.toString());
        }
    } catch (StaleElementReferenceException sere) {
        //Repeat it again
        MoveToElementAndClick(driver, locator);
    }

    this.log.debug("MoveToElementAndClick::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.
 * /*from  ww  w . j ava 2 s  .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.pivotal.gemfire.tools.pulse.tests.PulseBaseTests.java

License:Open Source License

public void mouseReleaseById(String id) {
    verifyElementPresentById(id);//from w  ww  .j av a  2 s. co m
    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);//ww  w  . j  a v  a 2 s.co  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.screenslicer.core.scrape.QueryKeyword.java

License:Open Source License

private static void hoverClick(RemoteWebDriver driver, WebElement element) throws ActionFailed {
    try {//from w w  w .  jav a 2 s  .com
        String oldHandle = driver.getWindowHandle();
        Actions action = new Actions(driver);
        Util.click(driver, element);
        action.moveByOffset(-MOUSE_MOVE_OFFSET, -MOUSE_MOVE_OFFSET).perform();
        action.moveToElement(element).perform();
        action.moveByOffset(2, 2).perform();
        Util.driverSleepShort();
        Util.cleanUpNewWindows(driver, oldHandle);
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:com.screenslicer.core.util.BrowserUtil.java

License:Open Source License

public static boolean click(Browser browser, WebElement toClick, boolean shift) {
    try {/*from w ww  .  java 2 s  .c  o m*/
        Actions action = new Actions(browser);
        action.moveToElement(toClick).perform();
        if (shift) {
            browser.getKeyboard().pressKey(Keys.SHIFT);
        }
        toClick.click();
        if (shift) {
            browser.getKeyboard().releaseKey(Keys.SHIFT);
        }
    } catch (Browser.Retry r) {
        throw r;
    } catch (Browser.Fatal f) {
        throw f;
    } catch (Throwable t) {
        return false;
    }
    return true;
}