Opening a web browser in full screen python
Asked Answered
M

3

5

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?

Misnomer answered 28/2, 2017 at 19:31 Comment(0)
M
12

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

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com')
driver.maximize_window()
Mythomania answered 28/2, 2017 at 19:36 Comment(2)
Fullscreen is different than maximized. That is why I down voted.Anglesey
Still, this is exactly what I've been looking for!Laurellaurella
P
1

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

Procto answered 23/4, 2020 at 13:37 Comment(0)
S
0

your code is nearly perfect. However, the only mistake is that your sequence is incorrect. Please refer to the updated code below.

        from selenium import webdriver
        
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get('https://google.com')
Saleswoman answered 31/7, 2023 at 6:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.