How to Resize Browser Window in WebDriver?

SeleniumAutomation TestingTesting Tools

We can resize the browser window in Selenium webdriver. We can configure the size of the browser with the help of the set_window_size method in Python.

The dimensions of the window size are passed as parameters to this method. Again, to get the size of the browser, we can use the method get_window_size.

Syntax

driver.set_window_size(200,500)

Example

Code Implementation

from selenium import webdriver
#set geckodriver.exe path
driver = webdriver.Firefox(executable_path="C:\\geckodriver.exe")
#maximize browser
driver.maximize_window()
#launch URL
driver.get("https://www.tutorialspoint.com/index.htm")
#new browser size
driver.set_window_size(800, 880)
#get window size
print(driver.get_window_size())
#close browser
driver.close()

Output

raja
Published on 29-Jun-2021 07:22:09
Advertisements