
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
Screenshot of a particular element with Python Selenium in Linux
We can capture a screenshot of a particular element with Selenium webdriver in Python. To achieve this task, first we have to identify the element which we want to identify with the help of any locators like id, xpath, css, name, class name, tagname, link text or partial link text.
After the element has been identified, we can capture its screenshot with the help of the screenshot method. We have to pass the file name where the screenshot shall be stored (along with extension) as a parameter to this method
Syntax
m=driver.find_element_by_tag_name("h4") m.screenshot("logo.png")
Let us capture the screenshot of the highlighted text below −
Example
from selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #identify element m = driver.find_element_by_tag_name("h4") #capture screenshot and save it in .png extension m.screenshot("screenshot_text.png") #browser quit driver.quit()
Output
- Related Articles
- How to get the screenshot of a particular element in the page in Selenium with python?
- Take screenshot of full page with Selenium Python with chromedriver.
- How to get the complete screenshot of a page in Selenium with python?
- How to take partial screenshot with Selenium WebDriver in python?
- How to take screenshot with Selenium WebDriver?
- How to get the values of a particular row in a table in Selenium with python?
- How to take partial screenshot (frame) with Selenium WebDriver?
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- Checking if element exists with Python Selenium.
- Take screenshot of the options in dropdown in selenium c#.
- How to get the value in a particular cell inside the worksheet in Selenium with python?
- Best way to take screenshot of a web page into Selenium?
- How to count the number of occurrences of a particular text inside a table in a page in Selenium with python?
- Shutter the ultimate linux screenshot program
- How to find the status of an element in a page in Selenium with python?

Advertisements