Opening and managing multiple instances of ChromeDriver WebDriver in C#

1,139 views
Skip to first unread message

Niels Nielsen

unread,
May 15, 2016, 10:56:40 PM5/15/16
to Selenium Users
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.

⇜Krishnan Mahadevan⇝

unread,
May 15, 2016, 11:00:07 PM5/15/16
to Selenium Users

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e56aef22-dd00-44fa-a8b3-962c73749508%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages