Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Python minimize browser window

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.

like image 776
Fedir Alifirenko Avatar asked Mar 07 '17 09:03

Fedir Alifirenko


People also ask

Can we minimize the browser in Selenium?

Unfortunately, Selenium does not provide any built-in function for minimizing the browser window. There is only the function for maximizing the window.

How do you minimize and maximize windows screen in Selenium?

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.

How do I resize a window in Selenium?

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.

How do I start Selenium minimized?

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.


1 Answers

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")
like image 79
Webln Avatar answered Oct 16 '22 02:10

Webln