

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capture a screenshot of a particular element in Selenium 4.0?
We can capture screenshots of a particular element in Selenium 4.0 with the help of getScreenshotAs(OutputType.File) method where the OutputType tells about the output type of the screenshot.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; public class ScreenshotsElement{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/tutor_connect/index.php"; WebElement drpdwn = driver.findElement(By.xpath("//select[@name=’selType’]")); // capture screenshot with getScreenshotAs() of the dropdown File f = drpdwn.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(f, new File(“screenshots.png”)); driver.quit(); } }
- Related Questions & Answers
- Screenshot of a particular element with Python Selenium in Linux
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How to get the screenshot of a particular element in the page in Selenium with python?
- How to get the screenshot of a particular section of the page like the logo of a website in Selenium with python?
- How to capture screenshots in Selenium?
- How to get the complete screenshot of a page in Selenium with python?
- Best way to take screenshot of a web page into Selenium?
- How to take screenshot with Selenium WebDriver?
- How to capture tooltip in Selenium using getAttribute?
- How can I capture network traffic of a specific page using Selenium?
- How to use relative xpath for locating a web-element by particular Attribute in Selenium?
- How to capture tooltip in Selenium using Actions Class?
- How to get screenshot of full webpage using Selenium and Java?
- How to delete a particular element from a JavaScript array?
- How to take partial screenshot (frame) with Selenium WebDriver?
Advertisements