Posts

Showing posts with the label Selenium

File Download at Custom Path in Selenium with C#

Image
This blog will show you how to download files from websites and save them to a folder. When you use selenium to download a file from a website, the file is saved in the default download folder. Chrome options must be used to save a downloaded file to the desired location. Let's see how we can do that. The code snippet below will download and save a file from a website. ChromeOptions() has been initialized here. In AddUserProfilePreference, download.default directory, enter the path of the directory where you want to save the downloaded file. using   OpenQA . Selenium ; using   OpenQA . Selenium . Chrome ; using   System ; using   System . Threading ; using   System . Windows . Forms ; using   WebDriverManager ; using   WebDriverManager . DriverConfigs . Impl ; using   WebDriverManager . Helpers ; private   void   DownloadButton_Click ( object   sender ,  EventArgs   e ) {      // Download the same ver...

File Upload in Selenium with C#

Image
The file upload is a simple process for transferring a file from a local computer to a website. This blog will demonstrate how to upload files to a website using Selenium and C#. In this section, I'll go over two methods for uploading files to a website. Method 1: The SendKeys() method is used in the first method. This SendKeys() method will assist in automatically entering text into the editable element. In this method, I'll pass the file location to be uploaded as a parameter to the SendKeys() method. The following code snippet shows how to upload a file in Selenium. The first three steps show how to launch a Chrome browser. Navigate to the URL in the fourth step. Then some waiting time was added. Finally, the file upload element was discovered, and the physical path of the image to upload was passed through the SendKeys method. private   void   UploadButton_Click ( object   sender ,  EventArgs   e ) {      // Download the same vers...

How to Take a Screenshot of an Element Hidden Under the Scrollbar using Selenium with C# .NET

Image
This blog is going to explain how to take a screenshot of the element which is hidden under the scrollbar. In selenium ((ITakesScreenshot)driver).GetScreenshot() takes a screenshot of the method page. Also, you can crop a specific element to capture. But when the image is hidden under the scroll bar. When you try to take a screenshot, the application will throw System.OutOfMemoryException: 'Out of memory.' error. Let's see how to take a screenshot of the element hidden under the scrollbar. The following is the console application code. In the code first, I have downloaded the ChromeDriver, which is the same version of the Chrome browser installed on my computer. Then I created the instance for the driver and navigated to the URL. Then scrolled to the location where the element is to be taken. Then I took a screenshot. Calculate the page y offset and find the difference with element Y location. Then cropped the element and saved it in the local machine. using Op...

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)         {              // Do...

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     {       ...

[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 ...