JohnB
JohnB

Reputation: 337

Take screenshot with selenium in Fullscreen mode

I am taking a screenshot by using selenium with no display. It's working but it would be nice if I could take a screenshot of the Fullscreen Browser (without Firefox Toolbar and so on, just the website). I tried the above code which should perform a F11 press. The code runs with no error, however Fullscreen is not working, so I guess the F11 command is somehow not executed. My OS is ubuntu.

Can somebody tell me how to take the screenshot in selenium in Fullscreen mode?

#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver

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

display = Display(visible=0, size=(1920, 1080))
display.start()

browser = webdriver.Firefox()
browser.get('http://www.google.com')

ActionChains(browser).send_keys(Keys.F11).perform()

browser.save_screenshot('screenshot.png')

browser.quit()
display.stop()

Upvotes: 4

Views: 1858

Answers (1)

inj3ct0r
inj3ct0r

Reputation: 209

just select one element on the page and send the keys ,

elem = driver.find_element_by_name("your_element")
elem.send_keys(Keys.F11)

make sure that element is loaded in DOM.It worked for me.

Upvotes: 1

Related Questions