Kevin
Kevin

Reputation: 217

How to get screenshot of equal size with selenium webdriver?

I am trying to take screenshot using Selenium Webdriver.

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(File_Location));

Now the issue is that for IE and Firefox the size of the screenshots differ even though I set dimension of window.

Can anybody give me suggestion how can I get screenshots of same size for all browser?

Upvotes: 4

Views: 6500

Answers (2)

Ardesco
Ardesco

Reputation: 7441

You can't.

The different drivers implement screenshots in different ways, IEDriver will produce differing sizes based upon the version of IE.

There have been a series of bugs raised on this, this one probably tells you all you need to know and validates this answer:

https://code.google.com/p/selenium/issues/detail?id=5332&can=1&q=screenshot%20size&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary

Specifically

Project Member #3 [email protected] Screenshots in the current WebDriver API mean full page screenshots. Unlike other browsers, the only way to get IE to render the full page is to have the IE window large enough to draw the entire page. In other words, to resize the window. For IE, we must either live with a resize, or not take full-page screenshots. This is a limitation of IE; there's nothing the IE driver can do to work around it. If you want to take a screenshot of only the visible viewport, without a resize, you can use the Windows API PrintWindow function. Status: WorkingAsIntended

Upvotes: 1

user2087450
user2087450

Reputation: 339

Try this:

EventFiringWebDriver efDriver = new EventFiringWebDriver(driver);
File scrFile = efDriver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(File_Location));

Upvotes: 0

Related Questions