使用Selenium Webdriver无头时出错

时间:2017-11-27 11:56:59

标签: c# selenium webdriver phantomjs

我正在使用chrome Webdriver在页面上截取屏幕截图,如果我使用“无头”参数我会收到此错误:

    [1127/115120.051:INFO:CONSOLE(157)] "Deprecation warning: moment 
    construction falls back to js Date. 
    This is discouraged and will be removed in upcoming major release. 
    Please refer to https://github.com/moment/moment/issues/1407 for more info.

        at Function.createFromInputFallback (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:157:187)
at ie (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:157:664)
at De (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:158:1390)
at Me (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:158:1287)
at Se (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:158:1007)
at Ne (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:158:1703)
at Oe (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:158:1737)
at t (https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js:154:2701)
at e (https://s-new.tradingview.com/static/bundles/blackfriday-dialog.dba1b059b906a510ba6c.js:1:580)
at i.<anonymous> (https://s-new.tradingview.com/static/bundles/blackfriday-dialog.dba1b059b906a510ba6c.js:1:2029)", source: https://s-new.tradingview.com/static/bundles/vendors.555f7dba06d6ca8b7950.4b2fc7ae22fe.js (157)

我不确定错误和信息消息是否相关。 同样的事情发生在使用phantomJS,但如果显示chrome窗口,则工作正常,尽管这不是一个选项,因为每次截屏时,chrome steals焦点。

这就是我正在尝试的事情:

         static void Main()
        {
             ChromeOptions options = new ChromeOptions();
             options.AddArgument("--disable-notifications");
             options.AddArguments("--disable-gpu");
             options.AddArgument("--headless");

             var driver = new ChromeDriver(options);

             driver.Url = "https://uk.tradingview.com/chart/?symbol=FX:GBPUSD";

             var webElement = driver.FindElementByClassName("chart-widget");
             string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".jpg";
             Byte[] byteArray = ((ITakesScreenshot)driver).GetScreenshot().AsByteArray;
             System.Drawing.Bitmap screenshot = new System.Drawing.Bitmap(new System.IO.MemoryStream(byteArray));
        }

错误发生在地址传递给driver.Url。

任何想法如何解决或解决它?

0 个答案:

没有答案