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

问题描述 投票:0回答:3
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)

public class Automate1 {public static void main(String [] args)引发IOException {System.setProperty(“ webdriver.chrome.driver”,“ C:\ Users \ DELL \ Downloads \ chromedriver.exe”); ...

java selenium-webdriver filenotfoundexception
3个回答
0
投票

替换


0
投票

Windows基本系统上文件系统分区的根文件夹(在您的情况下为C:)仅限于管理访问。根据设计,您不能仅以标准用户权限访问此文件夹。据我所知,这不是Java或Selenium问题。


-1
投票

创建新的File时,需要提供绝对路径

© www.soinside.com 2019 - 2024. All rights reserved.