List of usage examples for org.openqa.selenium.interactions Actions Actions
public Actions(WebDriver driver)
From source file:com.epam.jdi.uitests.web.selenium.elements.base.Element.java
License:Open Source License
public void focus() { invoker.doJAction("Scroll Element into the center of View and Focus on it", () -> { ((JavascriptExecutor) getDriver()).executeScript("arguments[0].scrollIntoView({block: 'center'});", getWebElement());//from w ww . jav a 2 s . co m Dimension size = getWebElement().getSize(); //for scroll to object new Actions(getDriver()).moveToElement(getWebElement(), size.width / 2, size.height / 2).build() .perform(); }); }
From source file:com.example.selenium.action.DoubleClick.java
@Test public void testDoubleClick() throws Exception { WebElement element = driver.findElement(By.id("div")); // Verify color is Blue Assert.assertEquals("rgba(0, 0, 255, 1)", element.getCssValue("background-color")); Thread.sleep(2000);// w w w . j a v a2s . c om Actions builder = new Actions(driver); builder.doubleClick(element).perform(); Thread.sleep(2000); //Verify Color is Yellow Assert.assertEquals("rgba(255, 255, 0, 1)", element.getCssValue("background-color")); }
From source file:com.example.selenium.action.DragDrop.java
@Test public void testDragDrop() throws InterruptedException { WebElement source = driver.findElement(By.id("d1")); WebElement target = driver.findElement(By.id("target")); Thread.sleep(2000);// ww w.j av a 2s . c o m Actions builder = new Actions(driver); builder.dragAndDrop(source, target).perform(); Thread.sleep(1000); WebElement element = driver.findElement(By.xpath("//div[2]/div")); Assert.assertNotNull(element); }
From source file:com.example.selenium.action.TableRowSelection.java
@Test public void testRowSelectionUsingControlKey() throws InterruptedException { List<WebElement> tableRows = driver.findElements(By.xpath("//table[@id='dataTables-example']/tbody/tr")); //Select second and fourth row from table using Control Key. //Row Index start at 0 Actions builder = new Actions(driver); builder.click(tableRows.get(0)).keyDown(Keys.CONTROL).click(tableRows.get(2)).keyUp(Keys.CONTROL).build() .perform();/*w ww.jav a 2 s. c o m*/ Thread.sleep(3000); }
From source file:com.fmb.common.BrowserEmulator.java
License:Apache License
/** * Hover on the page element//from ww w . ja v a2 s . com * * @param xpath * the element's xpath */ public void mouseOver(String xpath) { pause(stepInterval); expectElementExistOrNot(true, xpath, timeout); // First make mouse out of browser Robot rb = null; try { rb = new Robot(); } catch (AWTException e) { e.printStackTrace(); } rb.mouseMove(0, 0); // Then hover WebElement we = browserCore.findElement(By.xpath(xpath)); if (GlobalSettings.browserCoreType == 2) { try { Actions builder = new Actions(browserCore); builder.moveToElement(we).build().perform(); } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to mouseover " + xpath); } logger.info("Mouseover " + xpath); return; } // Firefox and IE require multiple cycles, more than twice, to cause a // hovering effect if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) { for (int i = 0; i < 5; i++) { Actions builder = new Actions(browserCore); builder.moveToElement(we).build().perform(); } logger.info("Mouseover " + xpath); return; } // Selenium doesn't support the Safari browser if (GlobalSettings.browserCoreType == 4) { Assert.fail("Mouseover is not supported for Safari now"); } Assert.fail("Incorrect browser type"); }
From source file:com.formkiq.web.WorkflowAddControllerIntegrationTest.java
License:Apache License
/** * Fill Signature./* w w w .ja v a2 s.c o m*/ * @param datafieldid {@link String} */ private void fillSignature(final String datafieldid) { WebElement element = findElementBy("canvas", "data-fieldid", datafieldid); final int startXY = 50; Actions builder = new Actions(getDriver()); Action drawAction = builder.moveToElement(element, startXY, startXY).clickAndHold() .moveByOffset(startXY, startXY).release().build(); drawAction.perform(); }
From source file:com.gargoylesoftware.htmlunit.html.ClickableElement2Test.java
License:Apache License
/** * @throws Exception if the test fails//from ww w.j av a2s . c o m */ @Test @Alerts("click click dblclick ") @BuggyWebDriver({ FF, CHROME }) public void dblClick() throws Exception { final String content = "<html>\n" + "<head>\n" + "<script>\n" + " function clickMe() {\n" + " document.getElementById('myTextarea').value+='click ';\n" + " }\n" + " function dblClickMe() {\n" + " document.getElementById('myTextarea').value+='dblclick ';\n" + " }\n" + "</script>\n" + "</head>\n" + "<body id='myBody' onclick='clickMe()' ondblclick='dblClickMe()'>\n" + "<textarea id='myTextarea'></textarea>\n" + "</body></html>"; final WebDriver driver = loadPage2(content); final Actions action = new Actions(driver); action.doubleClick(driver.findElement(By.id("myBody"))); action.perform(); assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("myTextarea")).getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchor2Test.java
License:Apache License
/** * FF behaves is different./* w w w .ja v a 2 s.co m*/ * @throws Exception if an error occurs */ @Test @Alerts(IE = "click href click doubleClick ", CHROME = "click href click href doubleClick ", FF = "click href click doubleClick href ") @BuggyWebDriver({ FF, CHROME }) @NotYetImplemented({ FF, IE }) public void doubleClick() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a id='myAnchor' " + "href=\"javascript:document.getElementById('myTextarea').value+='href ';void(0);\" " + "onClick=\"document.getElementById('myTextarea').value+='click ';\" " + "onDblClick=\"document.getElementById('myTextarea').value+='doubleClick ';\">foo</a>\n" + " <textarea id='myTextarea'></textarea>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Actions action = new Actions(driver); action.doubleClick(driver.findElement(By.id("myAnchor"))); action.perform(); assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("myTextarea")).getAttribute("value")); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @exception Exception If the test fails *//*from ww w . ja va2 s .c o m*/ @Test @BuggyWebDriver(IE) public void shiftClick() throws Exception { final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>Click Me</a>\n" + "</form></body></html>"; getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>"); final WebDriver driver = loadPage2(html); final WebElement link = driver.findElement(By.linkText("Click Me")); final String originalTitle = driver.getTitle(); final int windowsSize = driver.getWindowHandles().size(); new Actions(driver).moveToElement(link).keyDown(Keys.SHIFT).click().keyUp(Keys.SHIFT).perform(); assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size()); assertEquals("Should not have navigated away", originalTitle, driver.getTitle()); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java
License:Apache License
/** * @exception Exception If the test fails *//* w ww . j av a2 s .c o m*/ @Test @BuggyWebDriver({ IE, FF }) public void ctrlClick() throws Exception { final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>Click Me</a>\n" + "</form></body></html>"; getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>"); final WebDriver driver = loadPage2(html); final WebElement link = driver.findElement(By.linkText("Click Me")); final String originalTitle = driver.getTitle(); final int windowsSize = driver.getWindowHandles().size(); new Actions(driver).moveToElement(link).keyDown(Keys.CONTROL).click().keyUp(Keys.CONTROL).perform(); assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size()); assertEquals("Should not have navigated away", originalTitle, driver.getTitle()); }