Selenium Java to resize the Chrome browser window
KW.java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

class KW
{
    public static void main(String[] args) 
    {   
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        ChromeOptions co = new ChromeOptions();
        co.addArguments("window-size=700,700");
        
        DesiredCapabilities dc = DesiredCapabilities.chrome();
        dc.setCapability(ChromeOptions.CAPABILITY, co);
        
        WebDriver driver = new ChromeDriver(dc);
        driver.navigate().to("https://kodingwindow.com/testapp/");
        driver.close();
    }
}
Selenium Java to resize the Firefox browser window
KW.java
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

class KW
{
    public static void main(String[] args) 
    {   
        System.setProperty("webdriver.gecko.driver", "/home/kodingwindow/drivers/geckodriver");
        WebDriver driver = new FirefoxDriver();
        Dimension d = new Dimension(700, 700);
        driver.manage().window().setSize(d);
        driver.navigate().to("https://kodingwindow.com/testapp/");
        driver.close();
    }
}
Advertisement