Resize Browser Window in WebDriver



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

Updated on: 2021-06-29T07:24:18+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements