Opening a web browser in full screen python

13,006

Solution 1

If you're using selenium, just code like below:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com')
driver.maximize_window()

Solution 2

As suggested, selenium is a good way to accomplish your task.
In order to have it full-screen and not only maximized I would use:

chrome_options.add_argument("--start-fullscreen");

or

chrome_options.add_argument("--kiosk");

First option emulates the F11 pressure and you can exit pressing F11. The second one turns your chrome in "kiosk" mode and you can exit pressing ALT+F4.

Other interesting flags are:

chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])

Those will remove the top bar exposed by the chrome driver saying it is a dev chrome version.

The complete script is:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options    

chrome_options = Options()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
# chrome_options.add_argument("--start-fullscreen");
chrome_options.add_argument("--kiosk");

driver = webdriver.Chrome(executable_path=rel("path/to/chromedriver"),
                          chrome_options=chrome_options)
driver.get('https://www.google.com')

"path/to/chromedriver" should point to the chrome driver compatible with your chrome version downloaded from here

Share:
13,006
Couzy
Author by

Couzy

Updated on June 10, 2022

Comments

  • Couzy
    Couzy almost 2 years

    I am currently trying to code a basic smartmirror for my coding II class in high school with python. One thing I'm trying to do is open new tabs in full screen (using chrome). I currently have it so I can open url's, but I am not getting them in full screen. Any ideas on code I can use to open chrome in full screen?