How To Resize Browser Window Using Selenium WebDriver
In this post, we see how to Resize Browser Window using Selenium WebDriver. In some cases, we may need to resize browser window to some fixed dimensions, particularly when we are testing for responsive web design because we need to check to see how the different elements on the page render when we resize the browser window. Using Selenium WebDriver we could Resize Browser Window size. It allows resizing and maximizing window natively from its API.
To resize browser window to particular dimensions, we use ‘Dimension’ class to resize the browser window.
We know how to maximize the browser window to the maximum width and height of the screen.
driver.manage().window().maximize();
The below code opens the SoftwareTestingMaterial website and then set the browser window size to 480*620 .
package dummy; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.Test; public class ResizeBrowser { @Test public void launchBrowser() { System.setProperty("webdriver.gecko.driver","D://Selenium Environment//Drivers//geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.navigate().to("https://www.softwaretestingmaterial.com"); System.out.println(driver.manage().window().getSize()); //Create object of Dimensions class Dimension d = new Dimension(480,620); //Resize the current window to the given dimension driver.manage().window().setSize(d); System.out.println(driver.manage().window().getSize()); } }
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.
Hi,
Very nice Interview Questions of Selenium and Manual Testing
Thank you very much for Posting.