Recherche…


Introduction

Prendre des captures d'écran et enregistrer un chemin particulier

Syntaxe

  • Fichier src = (pilote (TakesScreenshot)) .getScreenshotAs (OutputType.FILE);
  • FileUtils.copyFile (src, nouveau fichier ("D: \ screenshot.png"));

JAVA

Code à prendre et enregistrer la capture d'écran:

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();
        }
    }
}

Capture d'écran:

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

Capture d'écran de la source à la destination:

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


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow