Tuesday 7 June 2022

How To Take Screenshot in Selenium Webdriver using Java | Selenium Screenshot Java

                   In this post, we will see How To Take Screenshot in Selenium Webdriver using Java | Selenium Screenshot Java 


Program Code:

import java.io.File;

import java.io.IOException;


import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


import com.google.common.io.Files;


public class Screenshot {


public static void main(String[] args) throws IOException {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://amazon.in");

driver.manage().window().maximize();

File f=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

Files.copy(f,new File("C:\\Users\\parag\\Downloads\\sample\\amazonscreenshot.jpg"));


}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=BV2S170h-ss

No comments:

Post a Comment