How can I take a screenshot with Selenium WebDriver?

后端 未结 30 2599
不知归路
不知归路 2020-11-21 07:48

Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

30条回答
  •  天涯浪人
    2020-11-21 08:20

    Java (Robot Framework)

    I used this method for taking a screenshot.

    void takeScreenShotMethod(){
        try{
            Thread.sleep(10000)
            BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
            ImageIO.write(image, "jpg", new File("./target/surefire-reports/screenshot.jpg"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    

    You may use this method wherever required.

提交回复
热议问题