🔧 AI Nachrichten How I’m using Codex and ChatGPT on my Mac(01.09.2026 um 00:00 Uhr)
🕵️ SicherheitslückenProFTPD mod_sql post-authentication SQLi RCE(06.09.2026 um 18:21 Uhr)
🕵️ Sicherheitslücken[remote] CVE-2026-42167 - ProFTPD mod_sql post-authentication SQLi - RCE(25.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] C-MOR 6.0104 - Cross-Site Scripting (XSS)(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] CubeCart 6.7.4 - Stored XSS(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] CubeCart 6.7.4 - Cross-Site Scripting(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] Langflow 1.8.4 - Path Traversal to Remote Code Execution(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] miniOrange 5.4.3 - Unauthenticated Auth Bypass(01.09.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] Wolf CMS 0.8.3.1 - RCE v(01.09.2026 um 02:00 Uhr)
🔧 AI Nachrichten How I’m using Codex and ChatGPT on my Mac(01.09.2026 um 00:00 Uhr)
🕵️ SicherheitslückenProFTPD mod_sql post-authentication SQLi RCE(06.09.2026 um 18:21 Uhr)
🕵️ Sicherheitslücken[remote] CVE-2026-42167 - ProFTPD mod_sql post-authentication SQLi - RCE(25.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] C-MOR 6.0104 - Cross-Site Scripting (XSS)(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] CubeCart 6.7.4 - Stored XSS(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] CubeCart 6.7.4 - Cross-Site Scripting(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] Langflow 1.8.4 - Path Traversal to Remote Code Execution(31.08.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] miniOrange 5.4.3 - Unauthenticated Auth Bypass(01.09.2026 um 02:00 Uhr)
🕵️ Sicherheitslücken[webapps] Wolf CMS 0.8.3.1 - RCE v(01.09.2026 um 02:00 Uhr)

🔧 Programmierung 🕛 vor 11 Monaten 3 Min Lesezeit
0

Taking Screenshots in Selenium with Python

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Python Selenium gives you multiple ways to capture the entire page, specific HTML elements, or even raw screenshot data.



Let's start!









1. Visible Viewport Screenshot



The simplest approach is capturing what’s currently visible in the browser window.




CODE
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.selenium.dev")

driver.save_screenshot("viewport.png") # user-friendly alias
# or
driver.get_screenshot_as_file("viewport_file.png") # same thing

driver.quit()







It captures only the visible viewport, not the full scrollable page.



Take into consideration that save_screenshot() is just a wrapper around get_screenshot_as_file(). Both return True on success, False on I/O errors.









2. Full-Page Screenshot



Capturing the entire page depends on the browser.






Firefox (native support):






CODE
from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://www.selenium.dev")

driver.get_full_page_screenshot_as_file("fullpage.png")









Chrome (using CDP):






CODE

import base64
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.selenium.dev")

# Ask Chrome for layout metrics (get full content size)
metrics = driver.execute_cdp_cmd("Page.getLayoutMetrics", {})
width = int(metrics["contentSize"]["width"])
height = int(metrics["contentSize"]["height"])

# Override device metrics so Chrome renders the ENTIRE page
# in a single "virtual" viewport (width x height).
driver.execute_cdp_cmd(
"Emulation.setDeviceMetricsOverride",
{
"mobile": False, # emulate desktop, not mobile
"width": width, # full content width
"height": height, # full content height
"deviceScaleFactor": 1, # 1 = normal DPI (increase for HiDPI/retina)
},
)

# Capture screenshot of this expanded surface
fullpage_screenshot = driver.execute_cdp_cmd(
"Page.captureScreenshot", {"fromSurface": True}
)

# Clear the override to restore normal browser behavior
driver.execute_cdp_cmd("Emulation.clearDeviceMetricsOverride", {})

# Save full page image to file
with open("screenshoot_fullpage_chrome.png", "wb") as f:
f.write(base64.b64decode(fullpage_screenshot["data"]))

driver.quit()






As of the time of writing, Chrome does not natively support full-page screenshots, so the CDP method is necessary. This will change once the WebDriver BiDi protocol is completely implemented.



After setting a custom viewport with Emulation.setDeviceMetricsOverride, it’s a good practice to call Emulation.clearDeviceMetricsOverride once the screenshot is taken.



Technically, this step isn’t required if your script ends right after capturing the screenshot, since the browser session will close anyway. However, leaving the override active can affect later interactions: the page may render as if it were displayed on an abnormally large monitor, causing layout issues or unexpected JavaScript behavior.



Clearing the override restores Chrome to its normal viewport, ensuring consistent behavior if you plan to keep browsing, testing, or taking additional screenshots in the same session.









3. Screenshot of a Specific HTML Element



Sometimes you don’t need the whole page, just a particular element. Selenium makes this easy with WebElement.screenshot().




CODE
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.python.org/")

element = driver.find_element(By.ID, "documentation")

# element.screenshot
element.screenshot(f"screenshot_webelement.png")

driver.quit()






Alternative: Get as PNG bytes




CODE
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.python.org/")

element = driver.find_element(By.ID, "documentation")

# Gets the screenshot of the current element as a binary data.
png_bytes = element.screenshot_as_png
with open("screenshot_webelement_bytes.png", "wb") as f:
f.write(png_bytes)

driver.quit()









Ok, we have reached the end of this article. I hope it helps 💪

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
1 Quelle
Windows 11’s useless Copilot key finally does something, you can map it to right-click
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Taking Screenshots in Selenium with Python

Thematisch verwandte Begriffe: Taking, Screenshots, Selenium, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...