Man must explore, and this is exploration at its greatest

Problems look mighty small from 150 miles up

Posted by Start Bootstrap on August 24, 2022

Window Handling

                    
Interface Window {
      
  void setSize(Dimension targetSize);
                    
  void setPosition(Point targetPosition);
                    
  Dimension getSize();
                    
  Point getPosition();
                    
  void maximize();
                    
  void fullscreen();
}
                                    
                  
                    
interface Window {

    /**
     * Get the size of the current window. This will return the outer window dimension, not just the
     * view port.
     *
     * 

See W3C WebDriver * specification for more details. * * @return The current window size. */ Dimension getSize(); /** * Set the size of the current window. This will change the outer window dimension, not just the * view port, synonymous to window.resizeTo() in JS. * *

See W3C WebDriver * specification for more details. * * @param targetSize The target size. */ void setSize(Dimension targetSize); /** * Get the position of the current window, relative to the upper left corner of the screen. * *

See W3C WebDriver * specification for more details. * * @return The current window position. */ Point getPosition(); /** * Set the position of the current window. This is relative to the upper left corner of the * screen, synonymous to window.moveTo() in JS. * *

See W3C WebDriver * specification for more details. * * @param targetPosition The target position of the window. */ void setPosition(Point targetPosition); /** * Maximizes the current window if it is not already maximized * *

See W3C WebDriver * specification for more details. */ void maximize(); /** * Minimizes the current window if it is not already minimized * *

See W3C WebDriver * specification for more details. */ void minimize(); /** * Fullscreen the current window if it is not already fullscreen * *

See W3C WebDriver * specification for more details. */ void fullscreen(); }



                    
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
  
public class WindowExample1 {
  public static void main(String[] args) throws Exception {
    WebDriverManager.chromedriver().setup();
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://www.w3schools.com");
    Thread.sleep(1000);
    System.out.println("Before changing the position: "+driver.manage().window().getPosition());
    driver.manage().window().setPosition(new Point(20, 65));
    Thread.sleep(1000);
    System.out.println("Aftre changing the position: "+driver.manage().window().getPosition());
    System.out.println("Before changing the size: "+driver.manage().window().getSize());
    Thread.sleep(1000);
    driver.manage().window().setSize(new Dimension(800, 900));
    System.out.println("After changing the size: "+driver.manage().window().getSize());
    Thread.sleep(1000);
    driver.manage().window().maximize();
    Thread.sleep(1000);
    driver.manage().window().fullscreen();
    Thread.sleep(1000);
    driver.quit();
  }
}