org.openqa.selenium.interactions.touch.TouchActions Java Examples
The following examples show how to use
org.openqa.selenium.interactions.touch.TouchActions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumberPickerSetMethod.java From xframium-java with GNU General Public License v3.0 | 6 votes |
private void clickAt( WebElement webElement, WebDriver webDriver, int x, int y ) { if ( webElement != null ) { Dimension elementSize = webElement.getSize(); int useX = (int) ((double) elementSize.getWidth() * ((double) x / 100.0)) + webElement.getLocation().getX(); int useY = (int) ((double) elementSize.getHeight() * ((double) y / 100.0)) + webElement.getLocation().getY(); if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof AppiumDriver ) { new TouchAction( (AppiumDriver) ((DeviceWebDriver) webDriver).getNativeDriver() ).press( PointOption.point( useX, useY ) ).perform(); } else if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof RemoteWebDriver ) { if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof HasTouchScreen ) new TouchActions( webDriver ).move( useX, useY ).click().build().perform(); else new Actions( webDriver ).moveByOffset(useX, useY ).click().build().perform(); } } }
Example #2
Source File: MobileElementState.java From ats-framework with Apache License 2.0 | 5 votes |
/** * Moves the focus to the specified element. Currently issued with tap */ @PublicAtsApi public void focus() { try { MobileElement mobileElement = (MobileElement) MobileElementFinder.findElement(appiumDriver, element); // use tap to focus new TouchActions(appiumDriver).singleTap(mobileElement).perform(); } catch (Exception se) { throw new MobileOperationException("Error trying to set the focus to " + getElementDescription(), se); } }
Example #3
Source File: DragDropGesture.java From xframium-java with GNU General Public License v3.0 | 5 votes |
@Override protected boolean _executeGesture( WebDriver webDriver ) { TouchActions dAction = new TouchActions( (WebDriver) ( (DeviceWebDriver) webDriver ).getNativeDriver() ); WebElement fromElement = (WebElement) getFromElement().getNative(); WebElement toElement = (WebElement) getToElement().getNative(); dAction.clickAndHold( fromElement ).moveToElement( toElement ).release().perform(); return true; }
Example #4
Source File: DragDropGesture.java From xframium-java with GNU General Public License v3.0 | 5 votes |
@Override protected boolean _executeGesture( WebDriver webDriver ) { WebElement fromElement = (WebElement) getFromElement().getNative(); Point fromPoint = new Point( fromElement.getLocation().getX() + ( fromElement.getSize().getWidth() / 2 ), fromElement.getLocation().getY() + ( fromElement.getSize().getHeight() / 2 ) ); Point toPoint = new Point( fromElement.getLocation().getX() + ( fromElement.getSize().getWidth() / 2 ), fromElement.getLocation().getY() + ( fromElement.getSize().getHeight() / 2 ) ); TouchActions tActions = new TouchActions( (WebDriver) ( (DeviceWebDriver) webDriver).getNativeDriver() ); tActions.down( fromPoint.getX(), fromPoint.getY() ).move( toPoint.getX(), toPoint.getY() ).release().perform(); return true; }
Example #5
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 5 votes |
public boolean _moveTo() { WebElement webElement = getElement(); if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0) { if (getWebDriver() instanceof HasInputDevices) { if (isTimed()) getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext()); if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver) { new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).moveTo(createPoint(webElement)).perform(); } else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver) { if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen) new TouchActions(getWebDriver()).moveToElement(webElement).build().perform(); else new Actions(getWebDriver()).moveToElement(webElement).build().perform(); } return true; } } return false; }
Example #6
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 5 votes |
public boolean _press() { WebElement webElement = getElement(); if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0) { if (getWebDriver() instanceof HasInputDevices) { if (isTimed()) getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext()); if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver) { new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).press(createPoint(webElement)).perform(); } else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver) { if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen) new TouchActions(getWebDriver()).clickAndHold(webElement).build().perform(); else new Actions(getWebDriver()).clickAndHold(webElement).build().perform(); } return true; } } return false; }
Example #7
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 5 votes |
public boolean _mouseDoubleClick() { WebElement webElement = getElement(); if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0) { if (getWebDriver() instanceof HasInputDevices) { if (isTimed()) getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext()); if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver) { new TouchActions((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).doubleTap(webElement).perform(); } else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver) { if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen) new TouchActions(getWebDriver()).doubleClick().build().perform(); else new Actions(getWebDriver()).doubleClick(webElement).build().perform(); } return true; } } return false; }
Example #8
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 5 votes |
public boolean _release() { WebElement webElement = getElement(); if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0) { if (getWebDriver() instanceof HasInputDevices) { if (isTimed()) getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext()); if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver) { new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).release().perform(); } else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver) { if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen) new TouchActions(getWebDriver()).release().build().perform(); else new Actions(getWebDriver()).release().build().perform(); } return true; } } return false; }
Example #9
Source File: TestdroidImageRecognition.java From test-samples with Apache License 2.0 | 5 votes |
public void androidSwipe(int startX, int startY, int endX, int endY) throws Exception { TouchActions actions = new TouchActions(driver); actions.down(startX, startY).perform(); sleep(0.5); actions.move(endX, endY).perform(); actions.up(endX, endY).perform(); }
Example #10
Source File: TestdroidImageRecognition.java From test-samples with Apache License 2.0 | 5 votes |
public void swipe(double startX, double startY, double endX, double endY) throws Exception { TouchActions actions = new TouchActions(driver); Dimension size = driver.manage().window().getSize(); Point screen = new Point(size.getWidth(), size.getHeight()); Point swipe_start = new Point(screen.x * startX, screen.y * startY); Point swipe_end = new Point(screen.x * endX, screen.y * endY); if (PlatformType.IOS.equals(PlatformType.IOS)) { iOSSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y); } else { androidSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y); } }
Example #11
Source File: AppiumAndroidTest.java From candybean with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testSlider() throws Exception { //get the slider WebElement slider = driver.findElement(By.xpath("//seek[1]")); // assertEquals(slider.getAttribute("value"), "50%"); TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0); // drag.perform(); // assertEquals(slider.getAttribute("value"), "0%"); }
Example #12
Source File: AppiumIosTest.java From candybean with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testSlider() throws Exception { //get the slider WebElement slider = driver.findElement(By.xpath("//slider[1]")); assertEquals(slider.getAttribute("value"), "50%"); TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0); drag.perform(); assertEquals(slider.getAttribute("value"), "0%"); }
Example #13
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 4 votes |
public boolean _clickFor( int length ) { WebElement webElement = getElement(); if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0) { if (getWebDriver() instanceof HasInputDevices) { if (isTimed()) getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext()); if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver) { new TouchAction((AppiumDriver<?>) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).press(createPoint(webElement)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(length))).release().perform(); } else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver) { CloudActionProvider aP = getWebDriver().getCloud().getCloudActionProvider(); Point clickLocation = aP.translatePoint(getWebDriver(), webElement.getLocation()); Dimension clickSize = aP.translateDimension(getWebDriver(), webElement.getSize()); Dimension windowSize = aP.translateDimension(getWebDriver(), getWebDriver().manage().window().getSize()); double x = clickLocation.getX() + (clickSize.getWidth() / 2); double y = clickLocation.getY() + (clickSize.getHeight() / 2); int percentX = (int) (x / windowSize.getWidth() * 100.0); int percentY = (int) (y / windowSize.getHeight() * 100.0); try { new TouchActions(getWebDriver()).longPress(webElement).build().perform(); } catch (Exception e) { ((DeviceWebDriver) getWebDriver()).getCloud().getCloudActionProvider().tap((DeviceWebDriver) getWebDriver(), new PercentagePoint(percentX, percentY, true), length); } } return true; } } return false; }
Example #14
Source File: TestdroidImageRecognition.java From test-samples with Apache License 2.0 | 4 votes |
public void selendroidTapAtCoordinate(int x, int y, int secs) throws Exception { TouchActions actions = new TouchActions(driver); actions.down(x, y).perform(); sleep(secs); actions.up(x, y).perform(); }