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?
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.