Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 445
BDeliers Avatar asked Sep 01 '26 02:09

BDeliers


2 Answers

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

like image 56
Sergio Saenz Avatar answered Sep 03 '26 17:09

Sergio Saenz


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()
like image 41
Danilo Matrangolo Marano Avatar answered Sep 03 '26 16:09

Danilo Matrangolo Marano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!