Take screenshot of full page with Selenium Python with chromedriver.

SeleniumAutomation TestingTesting Tools

We can take a screenshot of a full page with Selenium webdriver in Python with chromedriver. First of all, we shall obtain the original window size with the get_window_size method.

Then with the help of JavaScript Executor we shall fetch the complete height and width of the page which is opened on the browser. Then set the window size to that dimension with the set_window_size method.

Next, capture the screenshot of the entire content within the body tag in the html with the screenshot method. This method accepts the path of the screenshot that will be captured as a parameter.


from selenium import webdriver
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
#launch URL
#get window size
s = driver.get_window_size()
#obtain browser height and width
w = driver.execute_script('return document.body.parentNode.scrollWidth')
h = driver.execute_script('return document.body.parentNode.scrollHeight')
#set to new window size
driver.set_window_size(w, h)
#obtain screenshot of page within body tag
driver.set_window_size(s['width'], s['height'])


A new file called tutorialspoint.png gets created in the project folder.

Right−click on it and then select Properties. The Properties for pop−up comes up. Copy the location field.

Open it in a browser.

Published on 30-Jan-2021 17:35:26