Posts

Showing posts from April, 2022

In-Memory State Container Service in Blazor

Image
This blog is going to explain how to carry data from page to page or component. In the Blazor application, you can achieve this by injecting application state, dependency injection, and custom class. This state will persist in the browser's memory. So when the user navigates through the browser, they will get the same data. But this data will be cleared when the user refreshes the page. Let's look at the in-memory state process step by step. This example is going to illustrate how to manage in-memory state values from one child to another. Step1: First, I created the StateContainer class. StateContainer.cs  public class StateContainer {      public   List < string >  MovieList  { get ;  set ;} =  new   List < string >();        public   void   SetValue ( string   value )     {          MovieList . Add ( value );          NotifyStateChanged ();     }        public   event   Action ?  OnChange ;        private   void   NotifyStateChanged ()

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