Search code examples
selenium-webdriverwebdriverscreenshot

Selenium Webdriver - Capture URL in screenshot


I understand that the screenshot functionality basically works as painting the DOM. Since the URL is not part of the DOM, the screenshot does not contain the URL. But is there any workaround to capture the URL as part of the screenshot?


Solution

  • Currently it is not possible with webdriver.

    You can follow any of the below approaches. (You did not mention the programming language. These examples are in Java.)

    1. Capture current desktop screen

    Robot has createScreenCapture method. So, I would go with that & It is very easy to implement.

        Robot robot = new Robot();
        BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        ImageIO.write(screenShot, "JPG", new File("ScreenShot.jpg"));
    

    2. You can write the URL in the image.

    This might be an annoying approach sometimes as it might hide information in the image. But this too is very easy to implement.

    Check this answer

    3. Add the current URL to the image as meta data

    Check this answer