What are the different methods APIs provided by Selenium Webdriver to take screenshot of a webpage

0 votes
What are the different methods (APIs) provided by Selenium Webdriver to take screenshot of a webpage?
Jul 22, 2019 in Selenium by Hemant
575 views

1 answer to this question.

0 votes

Hey Hemant, Selenium Webdriver provides 3 different APIs to capture screenshot of a webpage. These are:

  1. save_screenshot()
  2. get_screenshot_as_file()
  3. 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);
answered Jul 22, 2019 by Abha
• 28,000 points

Related Questions In Selenium

0 votes
3 answers

What are the different ways to select an option from a dropdown using Selenium Webdriver?

So follow this steps for solution: First click ...READ MORE

answered Dec 15, 2020 in Selenium by Roshni
• 10,420 points
16,703 views
0 votes
1 answer

How to take screenshot of a frame using Selenium WebDriver?

you can use the below code: import java.awt.image.BufferedImage; import ...READ MORE

answered Jun 20, 2018 in Selenium by Meci Matt
• 9,460 points
1,819 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,651 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,488 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,317 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
3,928 views
0 votes
1 answer
0 votes
1 answer

How to capture screenshot of a webpage using Selenium Webdriver?

Hi Bindiya, you can use TakesScreenshot interface to capture the ...READ MORE

answered Jul 8, 2019 in Selenium by Abha
• 28,000 points
611 views