BDeliers
BDeliers

Reputation: 84

Full screen Firefox Python Selenium

I'm trying to start a full screen page in Firefox with Selenium in Python 3. The page opening works fine, but when I send the F11 key to the browser (the Full Screen key), anything happens. Here is my code :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

firefox = webdriver.Firefox()
firefox.get('http://localhost')
firefox.maximize_window()

body = firefox.find_element_by_tag_name('html')
body.send_keys(Keys.F11)

Does anyone know how to make my page start in full screen ? I know it's possible with Chrome, but it's harder with Firefox

Upvotes: 2

Views: 9148

Answers (3)

Selenium has a built-in method to make the window fullscreen: fullscreen_window()

Selenium API - fullscreen_window()

Invokes the window manager-specific ‘full screen’ operation

browser.get("https://www.screenku.com")
browser.fullscreen_window()

Upvotes: 2

Ringlayer Network
Ringlayer Network

Reputation: 21

pip3 install selenium pyautogui

#!/usr/bin/env python3
import pyautogui
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.webnotifications.enabled", False)
profile.set_preference("general.useragent.override", "Mozilla/5.0")
profile.update_preferences()
browser = webdriver.Firefox(firefox_profile=profile,executable_path = '/usr/local/bin/geckodriver')
browser.get("https://www.screenku.com")
pyautogui.press('f11')

Upvotes: 1

Sergio Saenz
Sergio Saenz

Reputation: 47

This is what worked for me.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()

driver.get('http://localhost')
driver.find_element_by_xpath('/html/body').send_keys(Keys.F11)

Hope this helps

Just realized I am using Python 2.6 vs your 3. Sorry about that, but at least you know it will work on an older Python version

Upvotes: 3

Related Questions