Fedir Alifirenko
Fedir Alifirenko

Reputation: 306

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.

Upvotes: 8

Views: 38951

Answers (5)

Tarun Dadlani
Tarun Dadlani

Reputation: 152

I would like to give a suggestion and make you correct that there's a method to minimize the window as you are required to do.

driver.minimize_window()

I would also like to mention that this will definitely work in python3, hope you were working in python.

Upvotes: 9

Webln
Webln

Reputation: 307

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")

Upvotes: 23

Isaias Prestes
Isaias Prestes

Reputation: 51

Just driver.minimize_window() or use a headless browser as PhamtonJS or Chromium.

Example:

PROXY_SERVER = "127.0.0.1:5566" # IP:PORT or HOST:PORT

options = webdriver.ChromeOptions()
options.binary_location = r"/usr/bin/opera" # path to opera executable
options.add_argument('--proxy-server=%s' % PROXY_SERVER)
driver = webdriver.Opera(executable_path=r"/home/prestes/Tools/operadriver_linux64/operadriver", options=options)
driver.minimize_window()
driver.get(url)

html = driver.page_source
soup = BeautifulSoup(html, "lxml")
print(html)

driver.quit()

Upvotes: 5

Sahil Agarwal
Sahil Agarwal

Reputation: 595

Maybe try a headless browser? Chrome headless or PhantomJS.

http://phantomjs.org/

Keep in mind that development is suspended for Phantom js. You may want to use other alternatives if it doesn't work or gives errors -

https://github.com/dhamaniasad/HeadlessBrowsers

A headless browser is a web browser without a GUI.

Upvotes: 3

Chanda Korat
Chanda Korat

Reputation: 2561

Try this,

driver.set_window_position(0, 0)

Upvotes: 1

Related Questions