4

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

I tried resizing the windows but no luck. I still get images of different size. Also how to implement PrintWindow function in java. Can you anybody provide a snippet of code that I can see.
I guess I wasn't clear and didn't put the first line of my answer in 48pt bold... YOU CAN'T get screenshots of a consistent size. Also using a Java Robot class won't help unless you are running the test on the machine that is driving the browser.
I was trying to follow project member comment "For IE, we must either live with a resize". My bad!
Can there be anything done taking same size screenshot for firefox?
There is no guarantee as to the screenshot size in any driver binding.
|
0

Try this:

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

2 Comments

I tried this code but still I am getting screenshots of different sizes.
Anybody else has some suggestion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.