Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi this is my problem how can i use
chromedriver(option) here
above
InitializeComponent();


i want to whole program use this driver instead of each time writing



What I have tried:

public partial class Form1 : Form
    {

          
        //selenium webdriver



            ChromeOptions options = new ChromeOptions();

            //this not working 

            ChromeDriver drivers = new ChromeDriver(options);


           // but this is working ||
          //                      \/

           ChromeDriver driver = new ChromeDriver();





        

        public Form1()
        {


            InitializeComponent();
        


        }
Posted
Updated 8-Dec-21 22:27pm

1 solution

An instance field initializer cannot reference other instance fields in the same class. You need to move the code to the constructor instead.

Fields - C# Programming Guide | Microsoft Docs[^]

C#
public partial class Form1 : Form
{
    private readonly ChromeOptions options;
    private readonly ChromeDriver driver;
    
    public Form1()
    {
        options = new ChromeOptions();
        driver = new ChromeDriver(options);
        InitializeComponent();
    }
 
Share this answer
 
Comments
Ashkan X 9-Dec-21 15:06pm    
That was awesome i was total confused for 5 days and you saved me thanks a lot idk how to thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900