I need to resize the browser as 300x400 during executing the Selenium automated tests. How can I resize the browser window in Selenium WebDriver (aka, Selenium 2) with Java?
[Note: It needs to resize the browser window for testing Responsive Web Design (RWD)]
Press Alt+Space to bring up the window menu, press S to choose the Size option, use the arrow keys to resize the window, and lastly Enter to confirm. Click the Maximize button in the top right corner of the window. Click the title bar and drag the window to the left, top, or right edge of the desktop.
Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.
Selenium provides a direct command to maximize the browser window. The following command is used to maximize the browser window. int width = 600; int height = 400; Dimension dimension = new Dimension(width, height); driver. manage().
You can get a reference to the current window with driver.manage().window()
. And the window
has a setSize()
method, so you could try
Dimension dimension = new Dimension(800, 600);
driver.manage().window().setSize(dimension)
For Responsive Design it's better if you don't use fixed data, in this case screen resolution - users need most often (cause it's much less prone to errors) :
_driver.manage().window().maximize();
or
_driver.manage().window().fullScreen();
If nothing works (to make tab in full screen only) for you, go for it:
driver.maximize_window()
where
driver = webdriver.Chrome(executable_path="D:\softwares\chromedriver.exe")
or could be any other webdriver locations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With