top of page

Selenium Python- Take Screen shot

How can one capture a screenshot using Selenium in Python?

# Import necessary libraries
import time
from selenium import webdriver
from import Service
from import By

# Create a new instance of the Chrome WebDriver
driver = webdriver.Chrome()

# Open the specified website

# Maximize the browser window

# Set an implicit wait of 3 seconds to allow elements to be found

# Pause the script execution for 3 seconds (using time.sleep)

# Locate the username field by ID and enter "standard_user"
driver.find_element(By.ID, "user-name").send_keys("standard_user")

# Locate the password field by ID and enter "secret_sauce"
driver.find_element(By.ID, "password").send_keys("secret_sauce")

# Click the login button using XPath
driver.find_element(By.XPATH, "//input[@id='login-button']").click()

# Pause the script execution for 5 seconds (waiting for the page to load or perform actions)

# Locate the specific element to capture by CSS selector
element_to_capture = driver.find_element(By.CSS_SELECTOR, ".inventory_item:nth-child(6)")

# Take a screenshot of the identified element and save it as screenshot.png"

# Alternatively, take a screenshot of the entire page and save it as "screenshot.png"

# Close the browser window

8 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a success message is displayed. package com.seleniumExamples2024; pu

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl + P: Print Ctrl + F: Find Windows Shortcuts: Windows Key: Open or


Mit 0 von 5 Sternen bewertet.
Noch keine Ratings

Rating hinzufügen
bottom of page