I want to take a screenshot of the full page of a website. Below are the website conditions
- It requires authentication with a sign in form
- The website I want to screenshot is rendered by Javascript (dynamic rendering), not static rendering
(inside the
body
tag is justscript
tags)
I did try some solutions I can find, but none of them work as I desired. Below are some attempt I tried
- Link This one required using headless chrome, which make me unable to fill the sign in form
- When I try to remove the headless options, I get this error
"message":"Cannot take screenshot with 0 height."
I guess this is because the content is rendered by Javascript. Note that I already give it some time to render withtime.sleep(5)
- When I try to choose another element, the result is varying. Some gives same error message as above, some give me the screenshot but not full page, just the visible part (same result as using
browser.save_screenshot()
). Below is the code I tried.
def S(X): return browser.execute_script(
'return document.querySelector("#main-layout-content").scroll'+X
)
browser = webdriver.Chrome()
browser.get('some link go here')
browser.set_window_size(S('Width') + 100, S('Height') + 1000)
#The print statement below work
print(S('Height'))
browser.find_element_by_id('main-layout-content').screenshot('web_screenshot.png')
Is there any way to achieve what I need?