Hello all,
I am new to coding/using selenium and I am trying to open x amount of webdriver instances dependant of a variable I have declared in an SQL database before the program starts.
I can not create the instances of webdrivers dynamically, as it only seems that I am able to create them manually in C#.
Currently the top of my code looks like this:
class Program
{
....
static IWebDriver driver = new ChromeDriver(@"C:\");
static IWebDriver driver2 = new ChromeDriver(@"C:\");
static IWebDriver driver3 = new ChromeDriver(@"C:\");
static IWebDriver driver4 = new ChromeDriver(@"C:\");
static int drivercounter = 1;
....
}
I am looping my DoStuffWithDriver method from the Main void, the method looks something like this
static void DoStuffWithDriver(List<string> data)
{
if (drivercounter == 1)
{
drivercounter++;
driver.Navigate().GoToUrl("http://www.website.com");
}
else if (drivercounter == 2)
{
drivercounter++;
driver2.Navigate().GoToUrl("http://www.website.com");
}
else if (drivercounter == 3)
{
drivercounter++;
driver3.Navigate().GoToUrl("http://www.website.com");
}
else if (drivercounter == 4)
{
drivercounter++;
driver4.Navigate().GoToUrl("http://www.website.com");
}
} My question is, if you can understand what I am trying to do from my poor example here, how can I make this entire process dynamic; create drivers and DoStuffWitherDriver in a loop? based on my int n? which in this example would be 4.
Thank you in advance.