While taking screenshot in selenium, if I use the dot(.) operator to mention the destination folder path instead of the full path, then the code is returning the error :
java.io.FileNotFoundException: .\Screenshot\shot1.jpeg (The system cannot find the path specified)
I am using the dot operator for the folder variable. As per my understanding the dot means, it represents the project folder. However, if I use the actual path "F:/SeleniumRevisit/Screenshot/shot1.jpeg", the code is working without any problem. My project folder is SeleniumRevisit which is present in F: drive. Any help would be appreciated.
Code :
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.io.FileHandler;
public class Screenshot_getScreenshotAs
{
public static void main(String[] args) throws InterruptedException, IOException
{
String key="webdriver.chrome.driver";
String value="./Drivers/chromedriver.exe";
System.setProperty(key,value);
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/simple_context_menu.html");
Thread.sleep(2000);
TakesScreenshot ts=(TakesScreenshot) driver;
File src=ts.getScreenshotAs(OutputType.FILE);
File dst=new File("./Screenshot/shot1.jpeg");
FileHandler.copy(src,dst);
}
}
You can try with user.dir give the folder and screenshot name