Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a web browser in full screen python

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?

like image 446
Couzy Avatar asked Feb 28 '17 19:02

Couzy


People also ask

How do I open the browser in full screen?

The fastest way to run Google Chrome in full-screen mode is to press the F11 key on your keyboard.

How do I open a Web browser in python?

Using the web browser in Python Under most circumstances, simply calling the open() function from this module will open url using the default browser . You have to import the module and use open() function.

How do I maximize a chrome window in python?

driver. fullscreen_window() works. driver. maximize_window() is more comfortable function that works with selenium chrome driver in python.


2 Answers

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

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com')
driver.maximize_window()
like image 123
Beomi Avatar answered Oct 18 '22 15:10

Beomi


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

like image 37
Lorenzo Sciuto Avatar answered Oct 18 '22 16:10

Lorenzo Sciuto