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 in Selenium by Hemant
46 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 by Abha
• 27,180 points

Related Questions In Selenium

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,420 points
787 views
0 votes
1 answer
0 votes
1 answer

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,110 points
933 views
0 votes
1 answer
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,130 points
1,114 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
856 views
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 in Selenium by Abha
• 27,180 points
83 views