HomeSelenium

Selenium Interview Question 54 – How to capture screen-shot in Selenium WebDriver?

Selenium Interview Question 54 – How to capture screen-shot in Selenium WebDriver?

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

What is the purpose of using Wrapper classes in Java?

Watch the answer for this Selenium Interview Question in a detailed manner in the below youtube video:

Note: Don’t forget to subscribe to my Youtube channel here: Click here

Notes used for explanation in this Youtube video are provided after the video:

Notes used in the above Youtube Video:

There are two ways to take screen-shots:

  • > Using Selenium WebDriver API (Preferred and most used)
  • > Using Robot Class of Java

Taking screen-shots using Selenium WebDriver API:

  • > We can take screenshots in Selenium using the predefined Interface and methods in Selenium.
  • > Demonstrate taking Screenshots in Selenium Projects – Demonstrate here
    • – Copy the below two lines of code, where ever we need to take screenshots and modify them accordingly
      • — File screenshotFile = ((TakeScreenshot)driver).getScreenshotAs(OutputType.File);
      • — FileUtils.copyFile(screenshotFile, new File(“screenshots\\screenshot1.jpg”));

To add more value to your answer, you can explain the second way of taking screen-shots using Robot class of Java:

Taking screen-shots using Robot Class of Java:

  • > Robot is a predefined Class in Java library
  • > Capturing Screenshot using Robot class
    • – Robot robot = new Robot();
    • – Rectangle area = new Rectangle(10,10,1000,800);
    • – File imageFile = new File(System.getProperty(“user.dir”)+”\\files\\capturedImage.png”);
    • – Thread.sleep(5000);
    • – ImageIO.write(bufferedImage, “png”, imageFile);

Next Steps:

  • > For more Selenium Interview Questions and answers, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Interview Questions list here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Arun Motoori

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *