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.gargoylesoftware.htmlunit.javascript.host.html.HTMLButtonElementTest.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from  w w w.j a v  a  2 s. co m*/
 */
@Test
@Alerts(FF = "mouse over [disabledBtn]")
public void mouseOverDiabled() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "  <head>\n"
            + "    <title>Test</title>\n" + "    <script>\n" + "    function dumpEvent(event) {\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 = '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"
            + "    <button id='disabledBtn' onmouseover='dumpEvent(event);' disabled>disabled button</button><br>\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);

    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("disabledBtn")));
    actions.perform();

    verifyAlerts(driver, getExpectedAlerts());
}

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

License:Apache License

/**
 * @throws Exception if an error occurs/*from   w w  w .  j  a  va2 s  .co m*/
 */
@Test
@Alerts({ "clicked", "fireEvent not available" })
public void fireEvent_WithoutTemplate() throws Exception {
    final String html = "<html>\n" + "  <head>\n" + "    <title>Test</title>\n" + "    <script>\n"
            + "    function doTest() {\n" + "      var elem = document.getElementById('a');\n"
            + "      if (!elem.fireEvent) { alert('fireEvent not available'); return }\n"
            + "      elem.fireEvent('onclick');\n" + "    }\n" + "    </script>\n" + "  </head>\n" + "<body>\n"
            + "  <div id='a' onclick='alert(\"clicked\")'>foo</div>\n"
            + "  <div id='b' onmouseover='doTest()'>bar</div>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("a")).click();
    verifyAlerts(driver, getExpectedAlerts()[0]);

    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("b")));
    actions.perform();
    verifyAlerts(driver, getExpectedAlerts()[1]);
}

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

License:Apache License

private void mouseOver(final String element) throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "  <head>\n"
            + "    <title>Test</title>\n" + "    <script>\n" + "    function dumpEvent(event) {\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 = '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" + "    " + element + "\n"
            + "  </form>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);

    final Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(By.id("tester")));
    actions.perform();/*from   ww  w  . j  ava  2  s. c o m*/

    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. j a  v  a  2 s .c  o 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 a2  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 w ww . ja  va  2s  . c  o m*/
 */
@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 w  w  .  jav  a 2  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 ww  w . ja va 2  s .c o  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.ggasoftware.jdiuitest.web.selenium.elements.base.Element.java

License:Open Source License

public void mouseOver() {
    invoker.doJAction("Move mouse over Element", () -> {
        getWebElement().getSize(); //for scroll to object
        Actions builder = new Actions(getDriver());
        builder.moveToElement(getWebElement()).build().perform();
    });//from  w w  w  .  j  a  va 2  s.co  m
}

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);/*w  w w.  j  a  va  2 s  .  c o m*/
        action.perform();
    });
}