1

I am trying to take a full screenshot of the whole html-page using the following code -

  • I would like to do this with selenium (not pyppeteer)
  • I am searching for a python solution (not Java)
  • I am searching for a non-headless solution (not headless)
  • I would like to do this with selenium (not seleniumbase)

Code:

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

options = Options()
srv=Service()
driver = webdriver.Chrome (service=srv, options=options)    
driver.maximize_window()
link = "https://rapidtech1898.com/"
driver.get (link)     
time.sleep(3) 
el = driver.find_element(By.XPATH,'(//body)[1]')
el.screenshot("test.png")
driver.quit()

But it is only taking the first part of the page and not the whole website till the bottom

enter image description here

How can I get the full html-site as a screenshot in non-headless mode?

7
  • This question is similar to: How to get screenshot of full webpage using Selenium and Java?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Nov 19 at 10:39
  • stackoverflow.com/questions/41721734/… Commented Nov 19 at 10:40
  • stackoverflow.com/a/53825388/15358800 Commented Nov 19 at 10:42
  • This question is similar to: Take screenshot of full page with Selenium Python with chromedriver. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Nov 19 at 10:42
  • Thanks for the link - but i am searching for another solution - - i am not searching for java - for python - and i am not searching for headless-mode - for non-headless mode (everything is stated in my initial question i would say - when i understand it correct your links are refreing to either a java-solution or a headless-solution) Commented Nov 19 at 11:46

1 Answer 1

0

import time

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.common.by import By

options = Options()

srv = Service()

driver = webdriver.Chrome(service=srv, options=options)

driver.maximize_window()

link = "https://rapidtech1898.com/"

driver.get(link)

time.sleep(3)

# 1) Get total page height and width using JS

total_width = driver.execute_script("return document.body.scrollWidth")

total_height = driver.execute_script("return document.body.scrollHeight")

# 2) Resize window to match full page

driver.set_window_size(total_width, total_height)

time.sleep(1) # small wait to let resize apply

# 3) Take full page screenshot

driver.get_screenshot_as_file("fullpage.png")

driver.quit()

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?
Also, while you’re at it, please revisit your formatting. The StackOverflow post authoring controls give you that ability—or you can you any standard Markdown capabilities.
this also doesn't work if the page is larger than the viewport, which is what OP's question is about

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.