LE: I see that quite a lot of people are interested in screenshots on the whole page, so I thought that I could update the answer with some positive points (silver bullets).
There are quite a few web testing frameworks that can (with minimal settings and effort) create a complete screenshot . I am from NodeJS testing environment, so I can only confirm the following: WebdriverIO and Google Puppeteer .
If anyone is interested in an easy way to do this with WebdriverIO, check this answer.
The short answer is NO, YOU CAN'T if you are using only Selenium (detailed explanation below). But what you can do is make most of the (monitor) of your device viewport .
So, launch your browser instance (driver) using ChromeOptions() , which is a method to configure the capabilities of ChromeDriver. We can do the following:
- maximize window (using
--start-maximized ); - switch to full screen mode (
F11 -key on Windows, Control+Cmd+F on Mac, using the switch --start-fullscreen ). - Note: A complete list of Chrome command line switches can be found here .
Your code should look like this:
// Setting your Chrome options (Desired capabilities) ChromeOptions options = new ChromeOptions(); options.add_argument('--start-maximized'); options.add_argument('--start-fullscreen'); // Creating a driver instance with the previous capabilities WebDriver driver = new ChromeDriver(options); // Load page & take screenshot of full-screen page driver.get("http://google.com"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Now, with regard to the problem with the full page, all drivers ( chromedriver , geckodriver , IEDriver , EdgeDriver , etc.) EdgeDriver standard WebDriver W3C . Thus, they depend on how the WebDriver team wants to show the functionality of the various functions, in our case, βScreenshotβ .
If you read the definition, it clearly states the following:
The Take Screenshot command takes a screenshot of the VIEWPORT top-level viewing contexts.
Outdated versions, some drivers could take a screenshot of the entire page (more on this here ), for example, the old FirefoxDriver, IEDriver, etc. This is no longer the case, as they all now implement the (literally) WebDriver W3C Standard.