WebDriver adjustBrowserPosition(Config config, WebDriver driver) { if (config.browserPosition() != null) { log.info("Set browser position to " + config.browserPosition()); String[] coordinates = config.browserPosition().split("x"); int x = Integer.parseInt(coordinates[0]); int y = Integer.parseInt(coordinates[1]); Point target = new Point(x, y); Point current = driver.manage().window().getPosition(); if (!current.equals(target)) { driver.manage().window().setPosition(target); } } return driver; }
@Override public void run() { counter.incrementAndGet(); if (!aborted) { WebDriver.Options options = driver.manage(); WebDriver.Window window = options.window(); /* * The API does not provide a method to check whether the window is closed, * but this method will throw an NPE if the window is closed. */ try { window.getPosition(); } catch (NullPointerException e) { System.out.format("[%d] could not obtain window position due to %s%n", counter.get(), e.toString()); abort(); } } }
public void robotPoweredMoveMouseToCoordinatesOnPage(int xCoordinates, int yCoordinates) { //Get Browser dimensions int browserWidth = driver.manage().window().getSize().width; int browserHeight = driver.manage().window().getSize().height; //Get dimensions of the window displaying the web page int pageWidth = Integer.parseInt(executor.executeScript("return document.documentElement.clientWidth").toString()); int pageHeight = Integer.parseInt(executor.executeScript("return document.documentElement.clientHeight").toString()); //Calculate the space the browser is using for toolbars int browserFurnitureOffsetX = browserWidth - pageWidth; int browserFurnitureOffsetY = browserHeight - pageHeight; //Calculate the correct X/Y coordinates based upon the browser furniture offset and the position of the browser on the desktop int xPosition = driver.manage().window().getPosition().x + browserFurnitureOffsetX + xCoordinates; int yPosition = driver.manage().window().getPosition().y + browserFurnitureOffsetY + yCoordinates; //Move the mouse to the calculated X/Y coordinates mouseObject.mouseMove(xPosition, yPosition); mouseObject.waitForIdle(); }
test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setPosition(new Point(5000, 5000)); test(driver.manage().window().getPosition().getX() == 224); test(driver.manage().window().getPosition().getY() == 168); driver.manage().window().setPosition(new Point(20, 50)); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); driver.manage().window().maximize(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().setPosition(new Point(20, 50)); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); test(driver.manage().window().getSize().getWidth() == 800); test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setSize(new Dimension(400, 200)); driver.manage().window().setPosition(new Point(10, 30)); test(driver.manage().window().getPosition().getX() == 10); test(driver.manage().window().getPosition().getY() == 30); test(driver.manage().window().getSize().getWidth() == 400);
} else { org.openqa.selenium.Dimension windowScreenSize = using_driver.manage().window().getSize(); Point startPoint = using_driver.manage().window().getPosition(); int width = windowScreenSize.width; int height = windowScreenSize.height;
} else { org.openqa.selenium.Dimension windowScreenSize = using_driver.manage().window().getSize(); Point startPoint = using_driver.manage().window().getPosition(); int width = windowScreenSize.width; int height = windowScreenSize.height;
public void robotPoweredMoveMouseToWebElementCoordinates(WebElement element) { //Get Browser dimensions int browserWidth = driver.manage().window().getSize().width; int browserHeight = driver.manage().window().getSize().height; //Get dimensions of the window displaying the web page int pageWidth = Integer.parseInt(executor.executeScript("return document.documentElement.clientWidth").toString()); int pageHeight = Integer.parseInt(executor.executeScript("return document.documentElement.clientHeight").toString()); //Calculate the space the browser is using for toolbars int browserFurnitureOffsetX = browserWidth - pageWidth; int browserFurnitureOffsetY = browserHeight - pageHeight; //Get the coordinates of the WebElement on the page and calculate the centre point int webElementX = ((Locatable) element).getCoordinates().inViewPort().x + Math.round(element.getSize().width / 2); int webElementY = ((Locatable) element).getCoordinates().inViewPort().y + Math.round(element.getSize().height / 2); //Calculate the correct X/Y coordinates based upon the browser furniture offset and the position of the browser on the desktop int xPosition = driver.manage().window().getPosition().x + browserFurnitureOffsetX + webElementX; int yPosition = driver.manage().window().getPosition().y + browserFurnitureOffsetY + webElementY; //Move the mouse to the calculated X/Y coordinates mouseObject.mouseMove(xPosition, yPosition); mouseObject.waitForIdle(); }
public Point getPosition() { return window.getPosition(); }
@Override public Point getWindowPosition() { return window.getPosition(); }
@Override public boolean validateWindowPosition(Point expected, Point epsilon) { Point actual = window.getPosition(); if (withinRange(expected.x, actual.x, epsilon.x) == false) return false; return withinRange(expected.y, actual.y, epsilon.y); }
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)); } }
@Override public Point getPosition() { ensureWebDriver(); return delegateWindow().getPosition(); }
@Override public Point getPosition() { return webDriver.manage().window().getPosition(); }