We can get the complete screenshot of a page in Selenium. While executing any test cases, we might encounter failures. To keep track of the failures we capture a screenshot of the web page where the error exists.
In a test case, there may be failure for reasons listed below −
For capturing the screenshot, save_screenshot() method is available. This method takes the full page screenshot.
In the arguments, we have to provide the screenshot file name along with the extension of .png. If anything else is used as extension, a warning message will be thrown and the image cannot be viewed.
The screenshot gets saved in the same path of the program.
Code Implementation for full page screenshot.
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() #to get the screenshot of complete page driver.save_screenshot("screenshot_tutorialspoint.png") #to close the browser driver.close()