List of usage examples for org.openqa.selenium.interactions Actions Actions
public Actions(WebDriver driver)
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptionElement2Test.java
License:Apache License
/** * @throws Exception if an error occurs/*from w w w .java 2 s . com*/ */ @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//from w ww . j av a 2s . 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 ww .j ava 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.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*w w w . ja v a 2 s . c o m*/ */ @Test // https://github.com/mozilla/geckodriver/issues/584 @BuggyWebDriver(FF) public void optionClickActions() throws Exception { final String html = "<html><body>\n" + "<select id='s' multiple>\n" + " <option selected value='one'>One</option>\n" + " <option value='two'>Two</option>\n" + " <option selected value='three'>Three</option>\n" + "</select>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement multiSelect = driver.findElement(By.id("s")); final List<WebElement> options = multiSelect.findElements(By.tagName("option")); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertTrue(options.get(2).isSelected()); new Actions(driver).click(options.get(0)).perform(); assertTrue(options.get(0).isSelected()); assertFalse(options.get(1).isSelected()); assertFalse(options.get(2).isSelected()); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.UIEventTest.java
License:Apache License
/** * @throws Exception if an error occurs/* w w w . j av a 2 s. c o 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.jdiuitest.web.selenium.elements.base.Element.java
License:Open Source License
public void doubleClick() { invoker.doJAction("Double click on Element", () -> { getWebElement().getSize(); //for scroll to object Actions builder = new Actions(getDriver()); builder.doubleClick(getWebElement()).perform(); });/*ww w . j a va 2s .c o m*/ }
From source file:com.ggasoftware.jdiuitest.web.selenium.elements.base.Element.java
License:Open Source License
public void rightClick() { invoker.doJAction("Right click on Element", () -> { getWebElement().getSize(); //for scroll to object Actions builder = new Actions(getDriver()); builder.contextClick(getWebElement()).perform(); });//from w ww . j ava 2 s. co m }
From source file:com.ggasoftware.jdiuitest.web.selenium.elements.base.Element.java
License:Open Source License
public void clickCenter() { invoker.doJAction("Click in Center of Element", () -> { getWebElement().getSize(); //for scroll to object Actions builder = new Actions(getDriver()); builder.click(getWebElement()).perform(); });// w ww. ja v a 2 s.co m }
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 va2s.c om }
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);// ww w. j a va 2 s . c o m action.perform(); }); }