请告诉我,我想使用PhantomJSDriver的多个实例:
PhantomJSDriver[] Driver = new PhantomJSDriver[memberscount];
for (int i = 0; i < memberscount; i++)
{
driverService[i] = PhantomJSDriverService.CreateDefaultService();
driverService[i].HideCommandPromptWindow = true;
driverService[i].LoadImages = false;
driverService[i].ProxyType = "http";
driverService[i].Proxy = proxy[i];
options[i] = new PhantomJSOptions();
options[i].AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
Driver[i] = new PhantomJSDriver(driverService[i], options[i]);
Driver[i].Manage().Window.Size = new Size(1920, 1080);
Driver[i].ExecutePhantomJS(script);
}
每个实例都运行良好,直到我尝试打开一个新的窗口/选项卡并打开其中的链接:
IJavaScriptExecutor jscript = Driver[count] as IJavaScriptExecutor;
jscript.ExecuteScript("window.open('', '_blank');");
Driver[i].SwitchTo().Window(Driver[i].WindowHandles[1]);
Driver[i].Navigate().GoToUrl(url);
此刻, Driver 的Second和所有后续实例开始将CPU加载10%,并且RAM呈指数增长,直到 phantomjs.ex e进程关闭本身(没有错误)
但是PhantomJSDriver的第一个实例即使在使用Windows的情况下也能稳定运行,只有在我使用第二个及其他驱动程序打开窗口时,问题才会开始。
试图这样打开:
Driver.ExecuteJavaScript("window.open('" + url + "', '_blank');");
还有同样的问题... 我如何找到原因?谢谢!
更新:
发现,在创建第二个附加窗口(第三个窗口)并点击链接后,也会发生这种情况:
url = "...1";
Driver[i].ExecuteScript("window.open('', '_blank');");
Driver[i].SwitchTo().Window(Driver[i].WindowHandles[1]);
Driver[i].Navigate().GoToUrl(url);
url = "...2";
Driver[i].ExecuteScript("window.open('', '_blank');");
Driver[i].SwitchTo().Window(Driver[i].WindowHandles[2]);
Driver[i].Navigate().GoToUrl(url); // After that, process crashing
CurrentWindowHandle变量可以,已经创建了第三个窗口,但是当与它交互时,该进程将关闭。