Fill Form Data Using Web Scrapping and C#

In this article,  we will learn Fill Form Data Using Web Scrapping In C#.

What is Web Scrapping?

  • Web scraping is the technique of extracting data from a website using bots.
  • Web scrapers allow you to extract data from websites automatically, saving you or your coworkers time that would otherwise be spent on tedious data collection chores. It also means that you can collect data in far bigger quantities than a single human could.

Note:  This is only for learning purposes. We do not motivate you to breach the terms of any website. So please use it for legal purposes only.

  • Let us understand with help of an example.

Step:1 Create a console project and will install three NuGet packages which are required for Web Scrapping.

  1. Selenium.Support
  2. Selenium.WebDriver
  3. Selenium.WebDriver.ChromeDriver

Step:2 Then you have to add your current browser version of chromedriver.exe and add it to your project folder, you can download it from here.

  • For example, my current chrome version is 99.0.4844.51

Step:3 Now create an MVC project and add this HTML code to your index.cshtml files.

    Layout = null;

<!DOCTYPE html>
<html lang="en">
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
    <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="txtName">Name:</label>
                        <input type="text" class="form-control" id="txtName">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="txtSurName">Surname:</label>
                        <input type="text" class="form-control" id="txtSurName">
            <div class="row">
                <div class="col-md-6">
                    <div class="checkbox">
                        <label><input type="checkbox" value="" id="chckGamming">Gamming</label>
                        <label><input type="checkbox" value="" id="chckMusic">Music</label>
                        <label><input type="checkbox" value="" id="chckCookingc">Cooking</label>
                        <label><input type="checkbox" value="" id="chckReading">Reading</label>
            <div class="row">
                <div class="col-md-6">
                    <div class="radio">
                        <label><input type="radio" name="optradio" id="rdMale">Male</label>
                        <label><input type="radio" name="optradio" id="rdFemale">Female</label>
            <div class="row">
                <div class="col-md-6">
                    <select id="ddSelect" name="ddSelect" class="form-control" required="">
                        <option value="1" selected>Select Option</option>
                        <option value="5">New Jersey</option>
                        <option value="6">Fort Pierce</option>
                        <option value="7">Plano</option>
                        <option value="8">Celina</option>
                        <option value="9">Palenstine</option>
            <div class="row">
                <div class="col-sm-6">
                    <label>Date Picker:</label>
                    <input type="date" id="dt" name="dt" class="form-control">
            <button type="button" class="btn btn-default mt-5 btn-primary" id="btnSubmit">Submit</button>
        $('#btnSubmit').click(function () {
            alert("Form submited sucessfully.");

Step:4 Run your MVC  project.

Step:5 Now create a Console application and add this code in your Program.cs file.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace WebScrapping
    class Program
        static void Main(string[] args)
                // add your chromedriver.exe path here
                ChromeDriver driver = new ChromeDriver(@"D:\Parth Mandaliya\WenScrapping\WenScrapping\Driver");

                //Maximize your browser size

                //Add your MVC project URL

                //Add your textbox id 

                //Add your checkbox id

                //Add your radio button id 

                //Add your select id which your have to select
                var select = new SelectElement(driver.FindElement(By.Id("ddSelect")));
                //Add your option text
                select.SelectByText("New Jersey");

                //Add your Date Picker id
                var toDateBox = driver.FindElement(By.Id("dt"));
                //This code is use for add date in Date Picker

                //Add your button id 
            catch (Exception ex)

Step:6 Run your Console application.


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories