No question about selenium operating PhantomJS browser interface hidden C # with a black console window

C # do automated testing with selenium, the current mainstream browser chrome and firefox browser, but chrome and firefox start slow, take up memory is relatively large, especially chrome and firefox in headless no interface mode, the query response is very slow the effect is not ideal. Sometimes do bulk queries when required speed, and full background operation, this time PhantomJS can come in handy, we can take it as a browser interface designed for non-browsing born, but unfortunately the latest version of selenium has not supported PhantomJS, currently only Selenium 3.0.0 version can drive PhantomJS, PhantomJS current latest version is 2.1.1 and is no longer updated, but nuget which can still download. In use, I found PhantomJS By default, it will jump out of a black console window, how to hide the window it is actually very simple, use the following code to start PhantomJS, make a mark, to prevent the stepped pit

        public PhantomJSDriver CreateDriver()
        {
            PhantomJSDriverService services = PhantomJSDriverService.CreateDefaultService();
            services.HideCommandPromptWindow = true;//隐藏控制台窗口
            return new PhantomJSDriver(services);
        }
          

 

Guess you like

Origin www.cnblogs.com/huang1314wei/p/11058084.html