Ricerca…


introduzione

Acquisizione di screenshot e salvataggio in un determinato percorso

Sintassi

  • File src = ((TakesScreenshot) driver) .getScreenshotAs (OutputType.FILE);
  • FileUtils.copyFile (src, new File ("D: \ screenshot.png"));

GIAVA

Codice per prendere e salvare screenshot:

public class Sample 
{
    public static void main (String[] args) 
    {
        *//Initialize Browser*
        System.setProperty("webdriver.gecko.driver", "**E:\\path\\to\\geckodriver.exe**");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();        
        driver.get("https://www.google.com/");
        
        //Take Screesnshot
        File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        try {
            //Save Screenshot in destination file
            FileUtils.copyFile(src, new File("D:\\screenshot.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Prende Screenshot:

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

Memorizza Screenshot dalla sorgente alla destinazione:

FileUtils.copyFile(src, new File("D:\\screenshot.png"));


Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow