I know how to call a method to maximize window from driver object.
driver.maximize_window()
But what method should I use when I need to minimize browser window (hide it)? Actually, driver object hasn't maximize_window attribute. My goal to work silently with the browser window. I don't want to see it on my PC.
Unfortunately, Selenium does not provide any built-in function for minimizing the browser window. There is only the function for maximizing the window.
We can maximize and minimize the browser while we are testing an application in Selenium. For maximizing the browser, maximize() method is to be used. For minimizing the browser, minimize() method is to be used. Both these methods can be used simultaneously in the same program.
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.
Selenium 4 gives you a brand new method named “minimize()” which can be used to minimize the browser just like a user normally do. “minimize” method is in inner interface “Window” of WebDriver interface.
Option 1: Use driver.minimize_window()
Option 2: Use --headless
Example 1:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
driver.get("enter your url here")
Example 2:
from selenium import webdriver
driver = webdriver.Chrome()
driver.minimize_window()
driver.get("enter your url here")
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