Reputation: 147
I tried to make a script with selenium, where it would open multiple windows/tabs of IE. Now, it would be easy, except for the fact, that I don't know how many tabs will be open.
This is what i have right now:
private void button1_Click(object sender, EventArgs e)
{
ilosc = Convert.ToInt32(numericUpDown1.Value);
Join();
}
private void Join()
{
for (int i = 0; i >= ilosc; i++)
{
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(@"https://google.com");
}
}
And I see a couple of problems here, like the variable name for IWebDriver
.
I also prefer it multi-threaded, since it won't lag the Form this way.
How can i open multiple windows/tabs using this method?
Upvotes: 0
Views: 316
Reputation: 147
Thanks to pcalkins, i managed to find a way! I made a new thread and started it when the Join() void was called. This is my final code:
private void button1_Click(object sender, EventArgs e)
{
ilosc = Convert.ToInt32(numericUpDown1.Value);
Join();
}
void Child()
{
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(@"https://google.com");
}
private void Join()
{
for (int i = 1; i <= ilosc; i++)
{
Thread thr = new Thread(Child);
thr.Start();
}
}
It now works perfectly!
Upvotes: 1