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.
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") driver.maximize_window() #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #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.find_element_by_tag_name('body').screenshot("tutorialspoint.png") driver.set_window_size(s['width'], s['height']) driver.quit()
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.