Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate Print screen button using selenium webdriver in Java

How to simulate Print screen button using selenium web driver in Java

Regards, Vignesh

like image 545
Vignesh Avatar asked Sep 27 '13 10:09

Vignesh


People also ask

Which method is used to capture a screenshot in Selenium WebDriver?

To take a screenshot in Selenium, we use an interface called TakesScreenshot, which enables the Selenium WebDriver to capture a screenshot and store it in different ways. It has a got a method “getScreenshotAs() ” which captures the screenshot and store it in the specified location.

How to take a screenshot in Selenium WebDriver?

In order to capture a screenshot in Selenium, one has to utilize the method Takes Screenshot. This notifies WebDriver that it should take a screenshot in Selenium and store it. Selenium WebDriver tool is used to automate web application testing to verify that it works as expected.

How to locate web elements automatically using selenium automation testing?

Wherever an ID is specified in the HTML code for any web element, you can leverage that in your Selenium automation testing scripts to locate that particular web element. The ID of a web element would always be unique which makes it a very powerful way to locate web elements automatically using Selenium automation testing.

How to use the selenium click button method?

You can use the Selenium click button method for various purposes such as selecting the radio button and checkbox or simply clicking on any button or link, drag and drop, click and hold, etc. In the next section, I am going to demonstrate the practical implementation of Selenium click button method in for basic operations, and advanced operations.

How do I test mouse click in selenium?

Performing Mouse Click/Left Click In Selenium Testing The most basic operation using a Selenium click button method is a left-click or a mouse click. Test Scenario: Visit LambdaTest Homepage and click on the Login button. Example code for the test scenario:


1 Answers

selenium doesn't support it, only web page shots. However you can use Robot to do it

try {
    String format = "jpg";
    String fileName = printScreen." + format;

    Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    Robot robot = new Robot();
    BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
    ImageIO.write(screenFullImage, format, new File(fileName));

} catch (AWTException | IOException ex) {
    System.err.println(ex);
}

And in C#

using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(@"C:\ScreenShots\printScreen.jpg", ImageFormat.Jpeg);
like image 199
Guy Avatar answered Sep 28 '22 13:09

Guy