简体   繁体   中英

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM