- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Take screenshot of the options in dropdown in selenium c#.
We can take screenshots of the options in dropdown with Selenium Webdriver. A screenshot is generally captured for the failure test cases. This is achieved with the help of ITakesScreenshot interface.
We shall take the help of GetScreenshot method to grab the screenshot. Finally, the SaveAsFile method is used where we pass the parameters – the path of the file and format of the image.
Syntax
((ITakesScreenshot)d). GetScreenshot().SaveAsFile("Screenshot.png",ScreenshotImageFormat.Png);
For implementation we shall be using the NUnit framework.
Example
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{ public class Tests{ String u ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"; IWebDriver d; [SetUp] public void Setup(){ //creating object of FirefoxDriver d = new FirefoxDriver(); } [Test] public void Test1(){ d.Navigate() .GoToUrl(u); d.Manage().Window.Maximize(); //identify dropdown IWebElement l = d.FindElement(By.Name("continents")); //scroll to dropdown ((IJavaScriptExecutor)d) .ExecuteScript("arguments[0].scrollIntoView(true);", l); l.Click(); //capture screenshot along file name ((ITakesScreenshot)d) .GetScreenshot().SaveAsFile("Screenshot.png", ScreenshotImageFormat.Png); } [TearDown] public void close_Browser(){ d.Quit(); } } }
Output
Right−click on the project in Solution Explorer. Then click on Open Folder in File Explorer.
Then move to folder bin−>Debug, the file named Screenshot.png should be available.
- Related Articles
- How to get all the options in the dropdown in Selenium?
- How to take screenshot with Selenium WebDriver?
- How to take partial screenshot with Selenium WebDriver in python?
- Take screenshot of full page with Selenium Python with chromedriver.
- How to take partial screenshot (frame) with Selenium WebDriver?
- Best way to take screenshot of a web page into Selenium?
- How to get all options of a dropdown using Python Selenium webdriver?
- Highlighting Dropdown Options in ReactJS
- How to verify if we can select multiple options in a static dropdown in Selenium?
- How to take screenshot in Android Programatically?
- JavaScript get the length of select options(dropdown)?
- How to programmatically take a screenshot in android?
- Screenshot of a particular element with Python Selenium in Linux
- How to get the number of options in the dropdown list with JavaScript?
- How to take a screenshot programmatically in iPhone/iOS?

Advertisements