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

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

Introduction

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

Prototype

public void perform() 

Source Link

Document

A convenience method for performing the actions without calling build() first.

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptionElement2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from w w  w  .java2  s.  co  m*/
 */
@Test
@Alerts(DEFAULT = { "o-mouse over [option1]", "s-mouse over [option1]" }, IE = {})
public void mouseOver() throws Exception {
    shutDownRealIE();

    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "  <head>\n"
            + "    <title>Test</title>\n" + "    <script>\n" + "    function dumpEvent(event, pre) {\n"
            + "      // target\n" + "      var eTarget;\n" + "      if (event.target) {\n"
            + "        eTarget = event.target;\n" + "      } else if (event.srcElement) {\n"
            + "        eTarget = event.srcElement;\n" + "      }\n" + "      // defeat Safari bug\n"
            + "      if (eTarget.nodeType == 3) {\n" + "        eTarget = eTarget.parentNode;\n" + "      }\n"
            + "      var msg = pre + '-mouse over';\n" + "      if (eTarget.name) {\n"
            + "        msg = msg + ' [' + eTarget.name + ']';\n" + "      } else {\n"
            + "        msg = msg + ' [' + eTarget.id + ']';\n" + "      }\n" + "      alert(msg);\n" + "    }\n"
            + "    </script>\n" + "  </head>\n" + "<body>\n" + "  <form id='form1'>\n"
            + "    <select name='select1' id='select1' size='2' onmouseover='dumpEvent(event, \"s\");' >\n"
            + "      <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");' >Option1</option>\n"
            + "      <option value='option2' id='option2'>Option2</option>\n" + "    </select>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("option1")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptionElement2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from   w  w w .  j  a  v a  2 s  .c o m*/
 */
@Test
@Alerts(DEFAULT = "o-mouse over [option1]", FF = { "o-mouse over [option1]",
        "s-mouse over [option1]" }, IE = {})
public void mouseOverDisabledSelect() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "  <head>\n"
            + "    <title>Test</title>\n" + "    <script>\n" + "    function dumpEvent(event, pre) {\n"
            + "      // target\n" + "      var eTarget;\n" + "      if (event.target) {\n"
            + "        eTarget = event.target;\n" + "      } else if (event.srcElement) {\n"
            + "        eTarget = event.srcElement;\n" + "      }\n" + "      // defeat Safari bug\n"
            + "      if (eTarget.nodeType == 3) {\n" + "        eTarget = eTarget.parentNode;\n" + "      }\n"
            + "      var msg = pre + '-mouse over';\n" + "      if (eTarget.name) {\n"
            + "        msg = msg + ' [' + eTarget.name + ']';\n" + "      } else {\n"
            + "        msg = msg + ' [' + eTarget.id + ']';\n" + "      }\n" + "      alert(msg);\n" + "    }\n"
            + "    </script>\n" + "  </head>\n" + "<body>\n" + "  <form id='form1'>\n"
            + "    <select name='select1' id='select1' size='2' disabled='disabled' "
            + "onmouseover='dumpEvent(event, \"s\");' >\n"
            + "      <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");'>Option1</option>\n"
            + "      <option value='option2' id='option2'>Option2</option>\n" + "    </select>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("option1")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptionElement2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from   ww  w . ja va 2 s  . c  om*/
 */
@Test
@Alerts(DEFAULT = {}, FF = { "o-mouse over [option1]", "s-mouse over [option1]" })
public void mouseOverDisabledOption() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "  <head>\n"
            + "    <title>Test</title>\n" + "    <script>\n" + "    function dumpEvent(event, pre) {\n"
            + "      // target\n" + "      var eTarget;\n" + "      if (event.target) {\n"
            + "        eTarget = event.target;\n" + "      } else if (event.srcElement) {\n"
            + "        eTarget = event.srcElement;\n" + "      }\n" + "      // defeat Safari bug\n"
            + "      if (eTarget.nodeType == 3) {\n" + "        eTarget = eTarget.parentNode;\n" + "      }\n"
            + "      var msg = pre + '-mouse over';\n" + "      if (eTarget.name) {\n"
            + "        msg = msg + ' [' + eTarget.name + ']';\n" + "      } else {\n"
            + "        msg = msg + ' [' + eTarget.id + ']';\n" + "      }\n" + "      alert(msg);\n" + "    }\n"
            + "    </script>\n" + "  </head>\n" + "<body>\n" + "  <form id='form1'>\n"
            + "    <select name='select1' id='select1' size='2' onmouseover='dumpEvent(event, \"s\");' >\n"
            + "      <option value='option1' id='option1' onmouseover='dumpEvent(event, \"o\");' "
            + "disabled='disabled'>Option1</option>\n"
            + "      <option value='option2' id='option2'>Option2</option>\n" + "    </select>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("option1")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java

License:Apache License

/**
 * @throws Exception if an error occurs/*w ww.  j a v a2  s. c o  m*/
 */
@Test
@Alerts("mouse over")
public void mouseOver() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <title>Test</title>\n" + "    <script>\n"
            + "    function doTest() {\n" + "      alert('mouse over');\n" + "    }\n" + "    </script>\n"
            + "  </head>\n" + "<body>\n" + "  <form id='form1'>\n"
            + "    <select name='select1' id='select1' size='4' onmouseover='doTest()'>\n"
            + "      <option value='option1' id='option1' >Option1</option>\n"
            + "      <option value='option2' id='option2'>Option2</option>\n" + "    </select>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("select1")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java

License:Apache License

/**
 * @throws Exception if an error occurs//from   w  w w.j a v a  2s. co m
 */
@Test
@Alerts(FF = "mouse over")
public void mouseOverDisabledSelect() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <title>Test</title>\n" + "    <script>\n"
            + "    function doTest() {\n" + "      alert('mouse over');\n" + "    }\n" + "    </script>\n"
            + "  </head>\n" + "<body>\n" + "  <form id='form1'>\n"
            + "    <select name='select1' id='select1' size='4' onmouseover='doTest()' disabled='disabled'>\n"
            + "      <option value='option1' id='option1'>Option1</option>\n"
            + "      <option value='option2' id='option2'>Option2</option>\n" + "    </select>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("select1")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.UIEventTest.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from ww w  .j av  a2  s.co m*/
 */
@Test
@Alerts(DEFAULT = { "[object Event]", "undefined", "[object MouseEvent]", "1", "[object MouseEvent]",
        "2" }, IE8 = { "[object]", "undefined", "[object]", "undefined", "[object]", "undefined" }, IE11 = {
                "[object Event]", "undefined", "[object PointerEvent]", "0", "[object PointerEvent]", "0" })
@BuggyWebDriver(FF31)
// FF31 has a detail of '1' for the double click but it is '2' when executed manually
public void detail() throws Exception {
    final String html = "<html><head><script>\n" + "  function alertDetail(e) {\n" + "    alert(e);\n"
            + "    alert(e.detail);\n" + "  }\n" + "</script></head>\n" + "<body onload='alertDetail(event)'>\n"
            + "  <div id='a' onclick='alertDetail(event)'>abc</div>\n"
            + "  <div id='b' ondblclick='alertDetail(event)'>xyz</div>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("a")).click();
    final Actions action = new Actions(driver);
    action.doubleClick(driver.findElement(By.id("b")));
    action.perform();
    assertEquals(getExpectedAlerts(), getCollectedAlerts(driver));
}

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

License:Open Source License

public void clickWithKeys(Keys... keys) {
    doJAction("Ctrl click on element", () -> {
        Actions action = new Actions(getDriver());
        for (Keys key : keys)
            action = action.keyDown(key);
        action = action.moveToElement(getWebElement()).click();
        for (Keys key : keys)
            action = action.keyUp(key);/*from  www .  j  av  a2  s.  c om*/
        action.perform();
    });
}

From source file:com.gwtplatform.carstore.cucumber.application.BasePage.java

License:Apache License

private void moveToElement(WebElement webElement) {
    Actions actions = new Actions(webDriver);
    actions.moveToElement(webElement);/*ww  w . j  a v  a2 s .c o m*/
    actions.perform();
}

From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextDefaultValueTester.java

License:Open Source License

@Test
public void runInputRichTextGeneralTest() {

    // 1. Navigate to the "inputRichText" "Default Value" use case.
    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputRichText", "default-value");

    // 2. Verify that "<p>This is some <strong>bold</strong> text<br />\nand this is some <em>italic</em> text.</p>"
    // appears in the *Model Value*.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertTextPresentInElement(
            "<p>This is some <strong>bold</strong> text<br />\nand this is some <em>italic</em> text.</p>",
            modelValue1Xpath);//from  w  w w. ja  va2s. c  om

    // 3. Before the text "ld text and this is some italic text.", type "ld o".
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    Actions insertText = browserDriver.createActions(BODY_XPATH);
    WebElement body = browserDriver.findElementByXpath(BODY_XPATH);
    insertText.click(body);

    for (int i = 0; i < "ld text and this is some italic text.".length(); i++) {
        insertText.sendKeys(Keys.LEFT);
    }

    insertText.perform();
    browserDriver.sendKeysToElement(BODY_XPATH, "ld o");

    // 4. Click the *Submit* button.
    String expectedText = "<p>This is some <strong>bold old</strong> text<br />\nand this is some <em>italic</em> text.</p>";
    submitRichText(browserDriver, submitButton1Xpath, 1, expectedText);

    //J-
    // 5. Verify that
    // "<p>This is some <strong>bold old</strong> text<br />\nand this is some <em>italic</em> text.</p>" appears in
    // the *Model Value*.
    //J+
    waitingAsserter.assertTextPresentInElement(expectedText, modelValue1Xpath);
}

From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java

License:Open Source License

protected static void selectTextAndSendKeys(BrowserDriver browserDriver, String completeText,
        String textToSelect, CharSequence... keys) {

    if (!completeText.contains(textToSelect)) {
        throw new IllegalArgumentException(
                "\"" + completeText + "\" does not contain \"" + textToSelect + "\"");
    }//from w  w  w.  j a v a 2s  .  com

    Actions boldAndItalicize = browserDriver.createActions(BODY_XPATH);
    WebElement body = browserDriver.findElementByXpath(BODY_XPATH);
    boldAndItalicize.click(body);

    for (int i = 0; i < completeText.length(); i++) {
        boldAndItalicize.sendKeys(Keys.LEFT);
    }

    int beginIndex = completeText.indexOf(textToSelect);

    for (int i = 0; i < beginIndex; i++) {
        boldAndItalicize.sendKeys(Keys.RIGHT);
    }

    boldAndItalicize.keyDown(Keys.SHIFT);

    for (int i = 0; i < textToSelect.length(); i++) {
        boldAndItalicize.sendKeys(Keys.RIGHT);
    }

    boldAndItalicize.keyUp(Keys.SHIFT);
    boldAndItalicize.perform();
    browserDriver.sendKeysToElement(BODY_XPATH, keys);
}