1

I have a problem with the headless chrome option. Get a completely blank page in the screenshot. I've used a few suggestions here on the forum, but nothing works. See code.

options = Options()
options.headless = True
options.add_argument("start-maximized")
options.add_argument("--window-size=1920,1080")
options.add_argument("--disable-gpu")
options.add_argument('--ignore-certificate-errors')
options.add_argument('--allow-running-insecure-content')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get_screenshot_as_file("screenshot.png")
fedordima
  • 47
  • 5

1 Answers1

1

Try this for headless (other option) and set window size, then you need to go to some webpage or it will take a empty screenshot.

options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1920x1080")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")
driver.get_screenshot_as_file("screenshot.png")
data_sc
  • 459
  • 1
  • 6
  • I get to google site and have a screenshot, but my website wich i need is always blank. Can you help? – fedordima Jun 22 '22 at 15:53
  • It is probably due to some security settings on the site. It's a big pharmaceutical company. How can I bypass all restrictions? – fedordima Jun 22 '22 at 16:03
  • Since I don't know the website your going to I don't know the exact issue. But you could wait for an element to appear first before taking a screenshot. Maybe the page wasn't loaded before the screenshot was taken. [link](https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python) – data_sc Jun 22 '22 at 16:06
  • can i give you the website private? I dont wanna show it here? – fedordima Jun 22 '22 at 16:15
  • Stack doesn't have a private chat option. I don't know it's even possible for a security setting that blocks screenshots from taking place. Did you test it and it works smoothly without being headless? – data_sc Jun 22 '22 at 16:42