Posts

Showing posts from March, 2022

How to Take a Screenshot of a Particular Element in Selenium with C# .NET

Image
This blog is going to explain how to take a screenshot of a particular element using selenium through C # .NET The following is a C# console application code. 1. ChromeDriver, the same version of the Chrome browser, was first downloaded. 2. The instance has been created and navigated to the webpage. 3. The element to be captured is found using the FindElement() method. 4. The screenshot was taken using the GetScreenshot() method. 5. The image taken is cropped using the Clone() method. 6. The finally cropped image is stored in the specified path. using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using System; using System.Drawing; using System.IO; using WebDriverManager; using WebDriverManager.DriverConfigs.Impl; using WebDriverManager.Helpers; namespace SampleConsoleApp {     class Program     {         static void Main(string[] args)         {              // Download the same version of chromedriver             var chromeDriverPath = new DriverManager(

How to Take a Screenshot in Selenium with C# .NET

Image
This blog is going to explain how to take a screenshot of a webpage using selenium through C # .NET You can achieve that in just 2 steps. First take a screenshot using the GetScreenshot() method. Then save it in location. //Take the screenshot Screenshot image = ((ITakesScreenshot)driver).GetScreenshot(); //Save the screenshot image.SaveAsFile(AppDomain.CurrentDomain.BaseDirectory+"//ScreenShot.png", ScreenshotImageFormat.Png); The following is a full C# console application code. In the code I have found the current version of the chrome browser and downloaded the same webdriver (Check this blog for more information) .Then I take a screenshot of the webpage and save it to the local storage. using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using System; using WebDriverManager; using WebDriverManager.DriverConfigs.Impl; using WebDriverManager.Helpers; namespace SampleConsoleApp {     class Program     {         static void Main(string[] args)

[Solved] session not created: This version of ChromeDriver only supports Chrome version xx (SessionNotCreated) - Selenium with C# .NET

Image
This blog is going to explain how to fix the ‘session not created: This version of ChromeDriver only supports Chrome version xx (SessionNotCreated)’ issue. That is how to get the same version of chrome browser and chromedriver. This problem is due to the fact that the Chrome browser version and the Chromedriver version are different. For example, the Chrome browser version you installed may be 98.0.4758.102 and your Chrome driver version may be 99.0.4844.51. To fix the problem, you need to download the same version of Chrome browser installed on your computer. Let's see how to achieve this. First you need to install the required packages using the nuget. To manage the WebDriver, install WebDriverManager package Install-Package WebDriverManager To manage selenium webdriver, install Selenium.WebDriver package Install-Package Selenium.WebDriver The final one is Sample Console Application code. The code below is a console application code. In the code, I got the