List of usage examples for org.openqa.selenium.interactions Actions Actions
public Actions(WebDriver driver)
From source file:com.digi.selenium.util.PageNavigation.java
protected void extra() { try {/*w ww .j a va 2 s .com*/ JavascriptExecutor jse = (JavascriptExecutor) getDriver(); jse.executeScript("window.scrollBy(0,500)", ""); // WebElement fb = (new WebDriverWait(fbdriver, 5000)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='main']/section/div/ul/li[1]/a"))); // fb.click(); //*[@id="main"]/section/div/ul/li[1]/a WebElement fb = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[1]/a")); Actions newTab1 = new Actions(getDriver()); newTab1.keyDown(Keys.SHIFT).click(fb).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base1 = getDriver().getWindowHandle(); Set<String> set1 = getDriver().getWindowHandles(); set1.remove(base1); assert set1.size() == 1; getDriver().switchTo().window((String) set1.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/a/i"))); //close the window getDriver().close(); getDriver().switchTo().window(base1); // handle windows change and switch back to the main window Thread.sleep(500); for (String winHandle1 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle1); // System.out.println("extra : FB Passed" ); log.info("FB Link Passed"); Thread.sleep(500); //*[@id="main"]/section/div/ul/li[2]/a WebElement tw = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[2]/a")); Actions newTab2 = new Actions(getDriver()); newTab2.keyDown(Keys.SHIFT).click(tw).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(500); //handle windows change String base2 = getDriver().getWindowHandle(); Set<String> set2 = getDriver().getWindowHandles(); set2.remove(base2); assert set2.size() == 1; getDriver().switchTo().window((String) set2.toArray()[0]); waitForPageLoad(500); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='page-container']/div[2]/div/div/div[1]/div/div/div/div[1]/h1/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base2); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle2 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle2); // System.out.println("extra : Twitter Passed" ); log.info("Twitter Link Passed"); Thread.sleep(5000); //*[@id="main"]/section/div/ul/li[3]/a WebElement com = getDriver().findElement(By.xpath("//*[@id='main']/section/div/ul/li[3]/a")); Actions newTab3 = new Actions(getDriver()); newTab3.keyDown(Keys.SHIFT).click(com).keyUp(Keys.SHIFT).build().perform(); Thread.sleep(5000); //handle windows change String base3 = getDriver().getWindowHandle(); Set<String> set3 = getDriver().getWindowHandles(); set3.remove(base3); assert set3.size() == 1; getDriver().switchTo().window((String) set3.toArray()[0]); waitForPageLoad(5000); //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='mainNav']/div[1]/div[1]/a"))); //close the window getDriver().close(); getDriver().switchTo().window(base3); // handle windows change and switch back to the main window Thread.sleep(2500); for (String winHandle3 : getDriver().getWindowHandles()) { getDriver().switchTo().window(winHandle3); // System.out.println("extra : Community Passed" ); log.info("Community Link Passed"); Thread.sleep(500); JavascriptExecutor jse1 = (JavascriptExecutor) getDriver(); jse1.executeScript("window.scrollBy(0,-500)", ""); } } } } catch (Exception e) { log.error("Failed to verify Social Media Links"); } }
From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java
License:Open Source License
/** * Do swipe up./* www. j ava 2 s . c o m*/ * @param element the element * @param xCoordinate the x coordinate * @param yCoordinate the y coordinate * @param distance the distance * @param speed the speed * @see com.ecofactor.qa.automation.mobile.action.UIAction#doSwipeUp(org.openqa.selenium.WebElement, * double, double, double, double) */ @Override public void doSwipeUp(final WebElement element, final double xCoordinate, final double yCoordinate, final double distance, final double speed) { setLogString("Swipe Up", true, CustomLogLevel.HIGH); new Actions(driverOps.getDeviceDriver()).dragAndDropBy(element, 0, (int) -distance).build().perform(); }
From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java
License:Open Source License
/** * Do swipe down.//from w ww . j a v a2s .c o m * @param element the element * @param xCoordinate the x coordinate * @param yCoordinate the y coordinate * @param distance the distance * @param speed the speed * @see com.ecofactor.qa.automation.mobile.action.UIAction#doSwipeDown(org.openqa.selenium.WebElement, * double, double, double, double) */ @Override public void doSwipeDown(final WebElement element, final double xCoordinate, final double yCoordinate, final double distance, final double speed) { setLogString("Swipe Down", true, CustomLogLevel.HIGH); new Actions(driverOps.getDeviceDriver()).dragAndDropBy(element, 0, (int) distance).build().perform(); }
From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java
License:Open Source License
/** * Drag element./* w ww .j a va 2 s. c o m*/ * @param srcElement the src element * @param xOffset the x offset * @param yOffset the y offset * @see com.ecofactor.qa.automation.platform.action.UIAction#dragElement(org.openqa.selenium.WebElement, * org.openqa.selenium.WebElement) */ @Override public void dragElement(final WebElement srcElement, final Integer xOffset, final Integer yOffset) { setLogString("Drag element..", true, CustomLogLevel.HIGH); final Actions builder = new Actions(driverOps.getDeviceDriver()); oneSec(); builder.clickAndHold(srcElement).build().perform(); oneSec(); builder.moveByOffset(xOffset, yOffset).build().perform(); }
From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java
License:Open Source License
/** * Drop element./* w ww . j av a 2 s . co m*/ * @param srcElement the src element * @see com.ecofactor.qa.automation.platform.action.UIAction#dropElement(org.openqa.selenium.WebElement) */ @Override public void dropElement(final WebElement srcElement) { setLogString("Drop element..", true, CustomLogLevel.HIGH); final Actions builder = new Actions(driverOps.getDeviceDriver()); builder.release(srcElement).build().perform(); oneSec(); }
From source file:com.elastica.webelements.HtmlElement.java
License:Apache License
/** * Click element in native way by Actions. * * <p/>//from w w w .j a va 2s.com * <pre class="code"> clickAt("1, 1"); * </pre> * * @param value */ public void clickAt(final String value) { captureSnapshot("before clicking"); TestLogging.logWebStep(null, "click on " + toHTML(), false); findElement(); String[] parts = value.split(","); int xOffset = Integer.parseInt(parts[0]); int yOffset = Integer.parseInt(parts[1]); try { new Actions(driver).moveToElement(element, xOffset, yOffset).click().perform(); } catch (InvalidElementStateException e) { e.printStackTrace(); element.click(); } try { BrowserType type = WebUIDriver.getWebUXDriver().getConfig().getBrowser(); if ((type == BrowserType.Chrome || type == BrowserType.InternetExplore) && this.getDriver().switchTo().alert().getText().contains("leave")) { this.getDriver().switchTo().alert().accept(); } } catch (NoAlertPresentException e) { e.printStackTrace(); } }
From source file:com.elastica.webelements.PageObject.java
License:Apache License
/** * Drags an element a certain distance and then drops it. * * @param element to dragAndDrop/*from w ww .ja va 2 s .c o m*/ * @param offsetX in pixels from the current location to which the element should be moved, e.g., 70 * @param offsetY in pixels from the current location to which the element should be moved, e.g., -300 */ public void dragAndDrop(final HtmlElement element, final int offsetX, final int offsetY) { TestLogging.logWebStep(null, "dragAndDrop " + element.toHTML() + " to offset(x,y): (" + offsetX + "," + offsetY + ")", false); element.captureSnapshot("before draging"); new Actions(driver).dragAndDropBy((WebElement) element.getElement(), offsetX, offsetY).perform(); element.captureSnapshot("after dropping"); }
From source file:com.epam.jdi.uitests.mobile.appium.elements.base.Clickable.java
License:Open Source License
public void clickByXY(int x, int y) { invoker.doJAction(format("Click on Element with coordinates (x,y) = (%s, %s)", x, y), () -> new Actions(getDriver()).moveToElement(getWebElement(), x, y).click().build().perform()); }
From source file:com.epam.jdi.uitests.mobile.appium.elements.base.Element.java
License:Open Source License
public void clickWithKeys(Keys... keys) { invoker.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 w ww .ja v a 2 s . com action.perform(); }); }
From source file:com.epam.jdi.uitests.mobile.appium.elements.base.Element.java
License:Open Source License
public void doubleClick() { invoker.doJAction("Double click on Element", () -> { Actions builder = new Actions(getDriver()); builder.doubleClick(getWebElement()).perform(); });//from w ww. jav a 2s . co m }