Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Use Selenium’s element-level screenshot method to save the target element directly, then hide a collapsible division only if it is a page-specific overlay or part of the element you selected. In Python, the basic call is element.screenshot("element.png"). If the unwanted division still appears, inspect the page to identify it, hide that specific element before capture, and check the result at the same viewport used by your automation.
Capture one Selenium element directly
When the desired image is a single DOM element, start with the element’s screenshot API rather than taking a screenshot of the entire browser and cropping it. The Selenium Python API documentation for Selenium 4.33.0 describes WebElement.screenshot(filename) as saving a screenshot of the current element to a PNG file. Selenium’s JavaScript API describes its capture as the visible region encompassed by the element’s bounding rectangle. The result is not a guarantee that every driver will render every element identically, so inspect the saved image in the browser and viewport you actually use.
Python example
This runnable example opens a page, locates one element, and writes a PNG. Install Selenium and a compatible browser driver for your environment before running it; replace the URL and CSS selector with values for your page.
from selenium import webdriver
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
# Uncomment to run Chrome without opening a visible window:
# options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
driver.set_window_size(1440, 1000)
driver.get("https://example.com")
target = driver.find_element(By.CSS_SELECTOR, "main")
target.screenshot("element.png")
finally:
driver.quit()
The Python method writes PNG output; it does not select an arbitrary output format through the filename. Choose a selector that identifies the content you mean to capture, not a broad parent that also contains the unwanted division.
#1 Best Overall
Java example
The Selenium official documentation’s Java example uses getScreenshotAs(OutputType.FILE) on a WebElement. This version saves the returned file to a chosen path:
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
WebDriver driver = new ChromeDriver();
try {
driver.manage().window().setSize(new org.openqa.selenium.Dimension(1440, 1000));
driver.get("https://example.com");
WebElement target = driver.findElement(By.cssSelector("main"));
File image = target.getScreenshotAs(OutputType.FILE);
Files.copy(image.toPath(), Path.of("element.png"));
} finally {
driver.quit();
}
Use the API for the language binding you run. Do not assume that taking a WebElement screenshot is equivalent to a full-page screenshot: the documented JavaScript behavior refers to the visible region within the element’s bounding rectangle.
Find out why the collapsible division appears
An unwanted dock, banner, or collapsible division can appear for different reasons. It may be inside the element you selected, or it may be page furniture that overlaps the target visually. The fix depends on which case applies.
If the division is inside the selected element
Use browser developer tools or inspect the DOM to determine the division’s relationship to the target. If it is a child or descendant, selecting a more specific element may exclude it without changing the page. Prefer this when the target content has its own stable selector. If the division is inseparable from the target’s DOM subtree, a page-specific style or script may be needed before capture.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteRank #2
If the division overlaps the target
A dock positioned over the target may not be a descendant of it. Identify the dock’s actual selector and state, then hide or collapse only that page element before taking the screenshot. The approach changes the page before capture; it is not a universal Selenium screenshot option.
A Stack Overflow answer for a particular New York Times COVID-19 map hid that page’s expanded dock by setting its visibility to collapse and its height to zero, captured the map element, then cropped unwanted margins and controls. Those selectors, styles, scroll position, and crop dimensions belong to that example. They should not be copied as if they were valid for arbitrary pages.
Hide a page-specific overlay before capture
Once you have verified the selector and confirmed that changing the page for a test capture is acceptable, you can use JavaScript through Selenium to alter the identified element. Replace .site-specific-dock with the real selector you inspected; the sample intentionally does not claim that a generic selector will work on other websites.
Rank #3
dock = driver.find_element(By.CSS_SELECTOR, ".site-specific-dock")
driver.execute_script(
"arguments[0].style.visibility = 'collapse'; "
"arguments[0].style.height = '0';",
dock,
)
target = driver.find_element(By.CSS_SELECTOR, ".map-container")
target.screenshot("map.png")
Before relying on the output, check that hiding the dock did not move, resize, or otherwise change the target in a way that makes the screenshot unsuitable. Some overlays are controlled by application state, and a style tweak may be overridden or may leave a gap. In that case, inspect the page’s DOM and layout again rather than broadening the selector to hide unrelated content.
Crop or mask leftover margins and controls
If the element screenshot is otherwise correct but still includes margins or controls, crop the saved PNG after capture. Cropping is a separate image-processing step, not a Selenium setting. The Stack Overflow map example used Pillow to crop and described masking map controls; its hard-coded pixel coordinates are specific to that page and viewport.
For your own page, determine the crop bounds from the actual PNG and keep them tied to the viewport and layout for which they were measured. A changed window size, responsive breakpoint, browser zoom, or page content can move the target and invalidate fixed coordinates. If the controls are part of the page and should disappear consistently, hiding them before capture may be more maintainable than masking their pixels afterward.
Rank #4
Choose the right capture approach
| Approach | Use it when | Trade-off |
|---|---|---|
| WebElement screenshot | The target is one element and its rendered content is the intended image. | Visible-region and driver behavior can vary; verify the result in the target environment. |
| Hide a site-specific overlay, then screenshot the element | A page-controlled dock or banner intrudes into the target capture. | You need the correct page-specific selector and style, and must check whether the layout changed. |
| Capture, then crop or mask | Only margins, branding, or controls need trimming. | Coordinates and dimensions can change with viewport and page layout. |
Reliability and troubleshooting
The image still contains the division
- Confirm that the located target is the intended element, rather than a parent that includes the division.
- Check whether the division is a descendant or an overlapping sibling/page element; those require different remedies.
- Verify that the page-specific selector matches the visible dock in its expanded state before applying the style.
- Inspect the saved PNG after the change. A screenshot API does not know which visual content you consider unwanted.
The image is clipped or incomplete
- Check whether the desired content is inside the element’s visible region. The JavaScript API reference describes a screenshot of the visible region encompassed by the element’s bounding rectangle.
- Compare the screenshot with the same browser window size and page state used when selecting the target.
- For non-W3C-conformant implementations, Selenium’s Java API documentation describes behavior as best effort; it notes a preference for entire element content and then the visible portion. Do not assume identical output across every driver.
The crop removes content or leaves controls
- Recalculate crop bounds from the current saved image rather than reusing coordinates from another page or viewport.
- Check responsive layout, scroll position, and whether the page loaded at the expected size.
- Where controls are consistently unwanted, consider hiding the page-specific control before capture instead of relying on a fixed crop or pixel mask.
The style change has no effect
- Confirm the selector points to the visible element and not a hidden duplicate.
- Check whether the site redraws or re-expands the dock after the script runs.
- Use the page’s actual expanded-state element and inspect the result before capturing. A solution tied to one website is not a general Selenium setting.
Or skip the browser setup
If you need a screenshot by URL rather than a Selenium-specific DOM workflow, ScreenshotNeo can return a screenshot or PDF with one GET request. Its clean-shot behavior accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and whether the request was billed. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture.
Install the Python requests package, set your API key, and change the target URL as needed. The API documentation is at https://screenshotneo.com/docs/.
Free tools Windows power users keep installed
One-click scans. No signup required.
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. To try it, sign up for free.
Frequently Asked Questions
Can Selenium save a WebElement screenshot as JPEG?
The documented Python element screenshot method saves a PNG. Convert the saved image separately if you need another format.
Best Value
Does Selenium have a built-in option to remove any collapsible division?
No general option is established here. Identify the page-specific element and adjust it before capture, or select a narrower target.
Will hiding an overlay work on every site?
No. The selector, styling, and effect are page-specific; verify the changed layout and screenshot on the target page.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

