Java Code Examples for org.openqa.selenium.Point#getX()
The following examples show how to use
org.openqa.selenium.Point#getX() .
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: PerfectoDeviceSteps.java From Quantum with MIT License | 6 votes |
/** * Performs the lo touch gesture according to the point coordinates. * * @param locator * write in format of x,y. can be in pixels or * percentage(recommended) for example 50%,50%. */ @Then("^I tap on \"(.*?)\" for \"(\\d*\\.?\\d*)\" seconds$") public static void tapElement(String locator, int seconds) { QAFExtendedWebElement myElement = new QAFExtendedWebElement(locator); Point location = myElement.getLocation(); Dimension size = myElement.getSize(); // determine location to click and convert to an appropriate string int xToClick = location.getX() + (size.getWidth() / 2); int yToClick = location.getY() + (size.getHeight() / 2); String clickLocation = xToClick + "," + yToClick; DeviceUtils.longTouch(clickLocation, seconds); }
Example 2
Source File: ReadElementAspect.java From opentest with MIT License | 6 votes |
@Override public void run() { super.run(); By locator = this.readLocatorArgument("locator"); WebElement element = this.getElement(locator); Point point = element.getLocation(); int x = point.getX(); int y = point.getY(); Dimension size = element.getSize(); int width = size.width; int height = size.height; this.writeOutput("x", x); this.writeOutput("y", y); this.writeOutput("width", width); this.writeOutput("height", height); }
Example 3
Source File: PerfectoDeviceSteps.java From Quantum with MIT License | 6 votes |
/** * Performs the double touch gesture according to the point coordinates. * * @param locator * write in format of x,y. can be in pixels or * percentage(recommended) for example 50%,50%. */ @Then("^I double click on \"(.*?)\"") public static void doubleClickElement(String locator) { QAFExtendedWebElement myElement = new QAFExtendedWebElement(locator); Point location = myElement.getLocation(); Dimension size = myElement.getSize(); // determine location to click and convert to an appropriate string int xToClick = location.getX() + (size.getWidth() / 2); int yToClick = location.getY() + (size.getHeight() / 2); String clickLocation = xToClick + "," + yToClick; DeviceUtils.doubleTouch(clickLocation); }
Example 4
Source File: SportsEventTributeTest.java From webDriverExperiments with MIT License | 5 votes |
@Test public void bounceThatWindow(){ WebDriver driver = new FirefoxDriver(); driver.get("file://" + System.getProperty("user.dir") + "/jsrunner.html"); driver.manage().window().maximize(); Dimension fullScreenSize = driver.manage().window().getSize(); int changeWidth = 200; int changeHeight = 210; int xDir = 8; int yDir = 8; int xDirIncrement = xDir; int yDirIncrement = yDir; driver.manage().window().setSize(new Dimension(changeWidth,changeHeight)); Point position = driver.manage().window().getPosition(); String banner = "***BANG****........ AND THEY ARE OFF........ Automation can be fun. " + " EvilTester.com present a javascript and browser" + " animation using Selenium 2 WebDriver tribute to the" + " sporting event that cannot be named lest we be sued"; int bannerStart = 0; for(int bounceIterations = 0; bounceIterations < 1000; bounceIterations ++){ position = position.moveBy(xDir,yDir); driver.manage().window().setPosition(position); if(position.getX()>(fullScreenSize.getWidth() - changeWidth)){ xDir = -1 * xDirIncrement; } if(position.getX()<0){ xDir = xDirIncrement; } if(position.getY()>(fullScreenSize.getHeight() - changeHeight)){ yDir = -1 * yDirIncrement; } if(position.getY()<0){ yDir = yDirIncrement; } //try {Thread.sleep(20);} catch (InterruptedException e) {} String displayBanner = banner.substring(bannerStart,bannerStart+30); ((JavascriptExecutor)driver).executeScript("document.title='" + displayBanner + "';"); bannerStart++; if(bannerStart > banner.length()-35){banner += banner;} } driver.quit(); }
Example 5
Source File: BaseIOSPickerWheelSteps.java From colibri-ui with Apache License 2.0 | 5 votes |
@Step @When("установить пикер в первое значение") public void setFirstPickerWheelValue() { WebElement webElement = driver.findElement(By.xpath(pickerWheelXPath)); Point center = ((IOSElement) webElement).getCenter(); Dimension size = webElement.getSize(); int height = size.getHeight(); Point target = new Point(center.getX(), center.getY() - (int) (height * stepToLast)); TouchAction touchAction = new TouchAction(driver); touchAction.press(point(target.getX(), target.getY())).release(); touchAction.perform(); }
Example 6
Source File: BaseIOSPickerWheelSteps.java From colibri-ui with Apache License 2.0 | 5 votes |
@Step @When("установить пикер в последнее значение") public void setLastPickerWheelValue() { WebElement webElement = driver.findElement(By.xpath(pickerWheelXPath)); Point center = ((IOSElement) webElement).getCenter(); Dimension size = webElement.getSize(); int height = size.getHeight(); Point target = new Point(center.getX(), center.getY() + (int) (height * stepToLast)); TouchAction touchAction = new TouchAction(driver); touchAction.press(point(target.getX(), target.getY())).release(); touchAction.perform(); }
Example 7
Source File: BasicMouseInterfaceTest.java From selenium with Apache License 2.0 | 5 votes |
@Test @Ignore(value = MARIONETTE, issue = "https://github.com/mozilla/geckodriver/issues/789") @NotYetImplemented(HTMLUNIT) @NotYetImplemented(SAFARI) @NotYetImplemented(EDGE) public void testMoveMouseByOffsetOverAndOutOfAnElement() { driver.get(pages.mouseOverPage); WebElement greenbox = driver.findElement(By.id("greenbox")); WebElement redbox = driver.findElement(By.id("redbox")); Point greenboxPosition = greenbox.getLocation(); Point redboxPosition = redbox.getLocation(); int shiftX = redboxPosition.getX() - greenboxPosition.getX(); int shiftY = redboxPosition.getY() - greenboxPosition.getY(); Dimension greenBoxSize = greenbox.getSize(); int xOffset = 2 - greenBoxSize.getWidth() / 2; int yOffset = 2 - greenBoxSize.getHeight() / 2; new Actions(driver).moveToElement(greenbox, xOffset, yOffset).perform(); shortWait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba())); new Actions(driver).moveToElement(greenbox, xOffset, yOffset) .moveByOffset(shiftX, shiftY).perform(); shortWait.until(attributeToBe(redbox, "background-color", Colors.RED.getColorValue().asRgba())); new Actions(driver).moveToElement(greenbox, xOffset, yOffset) .moveByOffset(shiftX, shiftY) .moveByOffset(-shiftX, -shiftY).perform(); shortWait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba())); }
Example 8
Source File: MobileElement.java From java-client with Apache License 2.0 | 5 votes |
/** * Method returns central coordinates of an element. * @return The instance of the {@link org.openqa.selenium.Point} */ public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
Example 9
Source File: Element.java From JTAF-ExtWebDriver with Apache License 2.0 | 5 votes |
@Override public int getLocationX() throws WidgetException { try { Point p = findElement().getLocation(); return p.getX(); } catch (Exception e) { throw new WidgetException("Error while fetching X location", locator, e); } }
Example 10
Source File: AbstractGesture.java From xframium-java with GNU General Public License v3.0 | 5 votes |
/** * Gets the actual point. * * @param percentagePoint the percentage point * @param screenDimension the screen dimension * @return the actual point */ protected Point getActualPoint( Point percentagePoint, Dimension screenDimension ) { if ( webElement != null ) { if ( webElement.getLocation() != null && webElement.getSize() != null && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0 ) { int x = percentagePoint.getX() * webElement.getSize().getWidth() + webElement.getLocation().getX(); int y = percentagePoint.getY() * webElement.getSize().getHeight() + webElement.getLocation().getY(); return new Point( x, y ); } } return new Point( (int) ( (percentagePoint.getX() / 100.0 ) * (double)screenDimension.getWidth() ), (int) ( (percentagePoint.getY() / 100.0 ) * (double)screenDimension.getHeight() ) ); }
Example 11
Source File: Coordinates.java From selenium-shutterbug with MIT License | 4 votes |
public Coordinates(Point point, Dimension size, Double devicePixelRatio) { this.width = (int)(size.getWidth()*devicePixelRatio); this.height = (int)(size.getHeight()*devicePixelRatio); this.x = (int)(point.getX()*devicePixelRatio); this.y = (int)(point.getY()*devicePixelRatio); }
Example 12
Source File: ScreenshotUtils.java From JTAF-ExtWebDriver with Apache License 2.0 | 4 votes |
/*** * You can use this method to take your control pictures. Note that the file should be a png. * * @param element * @param toSaveAs * @throws IOException * @throws WidgetException */ public static void takeScreenshotOfElement(IElement element, File toSaveAs) throws IOException, WidgetException { for(int i = 0; i < 10; i++) { //Loop up to 10x to ensure a clean screenshot was taken log.info("Taking screen shot of locator " + element.getByLocator() + " ... attempt #" + (i+1)); //Scroll to element element.scrollTo(); //Take picture of the page WebDriver wd = SessionManager.getInstance().getCurrentSession().getWrappedDriver(); File screenshot; boolean isRemote = false; if(!(wd instanceof RemoteWebDriver)) { screenshot = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE); } else { Augmenter augmenter = new Augmenter(); screenshot = ((TakesScreenshot) augmenter.augment(wd)).getScreenshotAs(OutputType.FILE); isRemote = true; } BufferedImage fullImage = ImageIO.read(screenshot); WebElement ele = element.getWebElement(); //Parse out the picture of the element Point point = ele.getLocation(); int eleWidth = ele.getSize().getWidth(); int eleHeight = ele.getSize().getHeight(); int x; int y; if(isRemote) { x = ((Locatable)ele).getCoordinates().inViewPort().getX(); y = ((Locatable)ele).getCoordinates().inViewPort().getY(); } else { x = point.getX(); y = point.getY(); } log.debug("Screenshot coordinates x: "+x+", y: "+y); BufferedImage eleScreenshot = fullImage.getSubimage(x, y, eleWidth, eleHeight); ImageIO.write(eleScreenshot, "png", screenshot); //Ensure clean snapshot (sometimes WebDriver takes bad pictures and they turn out all black) if(!isBlack(ImageIO.read(screenshot))) { FileUtils.copyFile(screenshot, toSaveAs); break; } } }
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: TwoFingerGesture.java From xframium-java with GNU General Public License v3.0 | 4 votes |
@Override protected boolean _executeGesture( WebDriver webDriver ) { String executionId = getExecutionId( webDriver ); String deviceName = getDeviceName( webDriver ); if ( executionId != null && deviceName != null ) { if ( webElement != null ) { CloudActionProvider aP = ( (DeviceWebDriver) webDriver ).getCloud().getCloudActionProvider(); Point at = aP.translatePoint( ( (DeviceWebDriver) webDriver), webElement.getLocation() ); Dimension size = aP.translateDimension( (DeviceWebDriver) webDriver, webElement.getSize() ); if ( at != null && size != null && size.getWidth() > 0 && size.getHeight() > 0 ) { int x = getStartOne().getX() * size.getWidth() + at.getX(); int y = getStartOne().getY() * size.getHeight() + at.getY(); Point swipeStart = new Point( x, y ); x = getEndOne().getX() * size.getWidth() + at.getX(); y = getEndOne().getY() * size.getHeight() + at.getY(); Point swipeEnd = new Point( x, y ); PerfectoMobile.instance(( (DeviceWebDriver) webDriver ).getxFID() ).gestures().pinch( executionId, deviceName, new PercentagePoint( swipeStart.getX(), swipeStart.getY(), false ), new PercentagePoint( swipeEnd.getX(), swipeEnd.getY(), false ) ); return true; } else { log.warn( "A relative elements was specified however no size could be determined" ); return false; } } PerfectoMobile.instance(( (DeviceWebDriver) webDriver ).getxFID() ).gestures().pinch( executionId, deviceName, new PercentagePoint( getStartOne().getX(), getStartOne().getY() ), new PercentagePoint( getEndOne().getX(), getEndOne().getY() ) ); return true; } else return false; }
Example 15
Source File: PERFECTOCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 4 votes |
@Override public Point translatePoint(DeviceWebDriver webDriver, Point currentPoint ) { log.error( "Translating potin from " + currentPoint ); if ( deviceWidth == 0 || deviceHeight == 0 ) { if ( webDriver.getPopulatedDevice().getResolution() == null ) { deviceWidth = -1; deviceHeight = -1; return currentPoint; } String[] deviceResolution = webDriver.getPopulatedDevice().getResolution().split( "x" ); if ( deviceResolution.length != 2 ) { deviceWidth = -1; deviceHeight = -1; return currentPoint; } try { deviceWidth = Integer.parseInt( deviceResolution[ 0 ] ); deviceHeight = Integer.parseInt( deviceResolution[ 1 ] ); } catch( Exception e ) { } log.error( "Resolution is " + deviceWidth + ", " + deviceHeight); if ( deviceWidth == 0 || deviceHeight == 0 ) { deviceWidth = -1; deviceHeight = -1; return currentPoint; } } if ( deviceWidth == -1 || deviceHeight == -1 ) return currentPoint; // // If we are here then we have a resolution // Point returnValue = new Point( currentPoint.getX(), currentPoint.getY() ); Dimension wD = webDriver.manage().window().getSize(); if ( deviceWidth > wD.getWidth() ) returnValue.x = returnValue.x * ( deviceWidth / wD.getWidth() ); else if ( deviceWidth < wD.getWidth() ) returnValue.x = returnValue.x * ( wD.getWidth() / deviceWidth ); if ( deviceHeight > wD.getHeight() ) returnValue.y = returnValue.y * ( deviceHeight / wD.getHeight() ); else if ( deviceHeight < wD.getHeight() ) returnValue.y = returnValue.y * ( wD.getHeight() / deviceHeight ); log.error( "New Point " + returnValue ); return returnValue; }
Example 16
Source File: AssertElementImage.java From opentest with MIT License | 4 votes |
/** * Capture the image of the target HTML element. * @param targetLocator The locator of the HTML element to capture. * @param ignoredElements The HTML elements ignored from the comparison. * @param scaleFactor For retina displays, this has to be set to 2. * @param ignoredPixelsColor The color that will be used to obscure the * HTML elements that are ignored from the comparison. * @return The image of the HTML element. */ private BufferedImage captureImage(By targetLocator, By[] ignoredElements, Double scaleFactor, Color ignoredPixelsColor) { WebElement targetElement = this.getElement(targetLocator); ShootingStrategy shootingStrategy = ShootingStrategies.viewportPasting(ShootingStrategies.scaling(scaleFactor.floatValue()), 100); AShot ashot = new AShot() .coordsProvider(new WebDriverCoordsProvider()) .shootingStrategy(shootingStrategy); // Hide scroll bars, so they don't impact the captured image JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; Object overflowValue = jsExecutor.executeScript("return document.querySelector('html').style.overflow"); if (!(overflowValue instanceof String)) { overflowValue = "initial"; } jsExecutor.executeScript("document.querySelector('html').style.overflow = 'hidden'"); Screenshot screenshot = ashot.takeScreenshot(driver, targetElement); BufferedImage capturedImage = screenshot.getImage(); jsExecutor.executeScript(String.format("document.querySelector('html').style.overflow = '%s';", overflowValue)); for (By by : ignoredElements) { Point targetElemLocation = targetElement.getLocation(); WebElement ignoredElement = this.getElement(by); Point ignoredElementLocation = ignoredElement.getLocation(); Dimension size = ignoredElement.getSize(); int width = size.width; int height = size.height; int relativeX = ignoredElementLocation.getX() - targetElemLocation.getX(); int relativeY = ignoredElementLocation.getY() - targetElemLocation.getY(); for (int xCoord = relativeX; xCoord < relativeX + width; xCoord++) { for (int yCoord = relativeY; yCoord < relativeY + height; yCoord++) { capturedImage.setRGB(xCoord, yCoord, ignoredPixelsColor.getRGB()); } } } return capturedImage; }
Example 17
Source File: SeleniumTest.java From gatf with Apache License 2.0 | 4 votes |
private static boolean checkRectangleOnTop(Rectangle trec, Rectangle orec) { Point tmid = new Point(trec.getX() + trec.getWidth()/2, trec.getY() + trec.getHeight()/2); return tmid.getX()>orec.getX() && tmid.getX()<(orec.getX()+orec.getWidth()) && tmid.getY()>orec.getY() && tmid.getY()<(orec.getY()+orec.getHeight()); }
Example 18
Source File: ScreenShoter.java From QVisual with Apache License 2.0 | 4 votes |
private static void setDriverPosition(WebDriver driver) { Point driverPosition = driver.manage().window().getPosition(); if (driverPosition.getX() > 0 || driverPosition.getY() > 23) { driver.manage().window().setPosition(new Point(0, 0)); } }
Example 19
Source File: ImageAnnotation.java From webtau with Apache License 2.0 | 4 votes |
protected Point center(WebElement webElement) { Point location = webElement.getLocation(); Dimension size = webElement.getSize(); return new Point(location.getX() + size.getWidth() / 2, location.getY() + size.getHeight() / 2); }
Example 20
Source File: DraggableWebElement.java From bobcat with Apache License 2.0 | 2 votes |
/** * Distance and direction from point drag to point drop in two-dimensional plane * * @param drag start point of drag * @param drop end point */ Offset(Point drag, Point drop) { this.x = drop.getX() - drag.getX(); this.y = drop.getY() - drag.getY(); }