- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
Selenium Webdriver - Capture Screenshots
We can capture screenshots with the Selenium webdriver using the save_screenshot method. The path of the screenshot captured is passed as a parameter to this method.
The syntax for capturing the screenshot is as follows −
driver.save_screenshot('logo.png')
Here, an image with the name logo.png should get saved within the project.
Code Implementation
The code implementation for capturing the screenshot is as follows −
from selenium import webdriver
driver = webdriver.Chrome(executable_path='../drivers/chromedriver')
#implicit wait time
driver.implicitly_wait(5)
#url launch
driver.get("https://www.tutorialspoint.com/index.htm")
#capture screenshot - tutorialspoint.png within project
driver.save_screenshot('tutorialspoint.png')
#close driver
driver.close()
Output
The output shows that an image tutorialspoint.png gets created within the project. It contains the captured screenshot.
Advertisements