尝试将屏幕截图粘贴到系统文件夹时出现 java.io.FileNotFoundException : c:\screenshot. png(访问被拒绝)错误

标签 java selenium-webdriver filenotfoundexception

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

        System.setProperty("webdriver.chrome.driver","C:\Users\DELL\Downloads\chromedriver.exe"); 
        WebDriver driver=new ChromeDriver(); 
        driver.manage().window().maximize(); 
        driver.manage().deleteAllCookies(); 
        driver.get("https://www.amazon.in"); 
        Select SC=new Select(driver.findElement(By.xpath("//select[@id='searchDropdownBox']"))); 
        //Selecting an option from drop down by using Select class
        SC.selectByVisibleText("Books"); driver.findElement(By.xpath("//input[@id=\"twotabsearchtextbox\"]")).sendKeys("The God Father"); 
        driver.findElement(By.xpath("//input[@class=\"nav-input\"]")).click(); 
        JavascriptExecutor Scroll = ((JavascriptExecutor) driver); 
        //For Scrolling Functionality 
        Scroll.executeScript("scroll(0,800)"); 
        //Scrolling Up
        Scroll.executeScript("scroll(0,-200)"); 
        //Scrolling down 
        driver.findElement(By.linkText("The Godfather")).click(); 
        ArrayList Handles=new ArrayList(driver.getWindowHandles()); 
        driver.switchTo().window(Handles.get(1)); 
        Select Q=new Select(driver.findElement(By.id("quantity"))); 
        Q.selectByIndex(1); 
        driver.findElement(By.id("add-to-cart-button")).click(); 
        driver.close(); 
        driver.switchTo().window(Handles.get(0)); 
        TakesScreenshot scrShot =((TakesScreenshot)driver); 
        File SrcFile=scrShot.getScreenshotAs(OutputType.FILE); 
        File DestFile=new File("c:\screenshot.png"); 
        FileUtils.copyFile(SrcFile, DestFile);

错误:

Exception in thread "main" java.io.FileNotFoundException: c:\screenshot.png (Access is denied)

最佳答案

替换

File DestFile=new File("c:\screenshot.png"); 

File DestFile=new File("c:/screenshot/screenshot.png"); 

关于尝试将屏幕截图粘贴到系统文件夹时出现 java.io.FileNotFoundException : c:\screenshot. png(访问被拒绝)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59144607/

相关文章:

java - Android FileNotFoundException 即使文件可用且设置了权限

Java 链表问题

firefox - 接收org.openqa.selenium.WebDriverException : Cannot find firefox binary in PATH running tests in Selenium IDE with Webdriver playback

java - 部署到不同机器时如何使用selenium/standalone-chrome?

java - 尝试在 Java 中创建 FileReader 时出现 FileNotFoundException

java - 找不到.txt文件的原因?

java - LinkedBlockingQueue 中 put() 的性能

java - 如何正确使用 Hibernate @Index 注解?

java - 自动生成id

selenium - 使用机器人框架(Seleniumlibrary)验证 alt 标签不应为空