Hey Hemant, Selenium Webdriver provides 3 different APIs to capture screenshot of a webpage. These are:
- save_screenshot()
- get_screenshot_as_file()
- get_screenshot_as_png()
To understand all three methods, checkout this script:
driver = webdriver.Firefox();
driver.get("https://www.facebook.com/");
driver.save_screenshot('screenshot_1.png');
driver.get_screenshot_as_file('screenshot_2.png');
screenshot = driver.get_screenshot_as_png();
screenshot_size = (20, 10, 480, 600);
image = Image.open (StringIO.StringIO(screen));
region = image.crop(screenshot_size);
region.save('screenshot_3.jpg', 'JPEG', optimize=True);