-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenshots_Example.java
43 lines (28 loc) · 1.24 KB
/
Screenshots_Example.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Screenshots_Example {
public static WebDriver driver;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "F:\\Selenium\\geckodriver.exe"); //*Provide path of geckodriver on your system
driver = new FirefoxDriver();
driver.get("https://hdfcbank.com/");
driver.manage().window().maximize();
captureScreenshots("homepage");
driver.findElement(By.linkText("Register")).click();
captureScreenshots("register_page");
}
public static void captureScreenshots(String filename) throws IOException
{
TakesScreenshot objScreenshot = ((TakesScreenshot)driver);
File objSrcFile =objScreenshot.getScreenshotAs(OutputType.FILE);
File objDestFile = new File("F:\\Selenium\\Snapshots\\" + filename + ".jpg"); //* Provide any path on your system.
FileUtils.copyFile(objSrcFile,objDestFile);
}
}