我需要将页面保存为PDF但我遇到了问题 . 我正在使用ChromeDriver并仅使用谷歌作为示例(因为我的应用需要登录)我导航到该页面(google.com) . 然后在javascript中执行window.print()以获取打印窗口 . Chrome打开了打印预览页面,我得到iframe的src显示pdf,所以我可以从网址中提取pdf .

我的问题是,在我执行javascript时,它会打开打印预览,但执行会在那里停止 . 这就像ChromeDriver正在等待页面说它已经完成但消息永远不会出现所以我收到一个WebDriverException,说它超时了 .

奇怪的是,直到昨天我收到一堆Windows更新并更新了包括Chrome在内的一系列程序 .

那么有谁知道如何再次使这项工作?

我正在使用Google Chrome版本62.0.3202.94(官方版本)(64位)操作系统是Windows 10 ChromeDriver版本是2.33.0 Selenium WebDriver是3.7.0

这是错误:

OpenQA.Selenium.WebDriverException:对URL http:// localhost:12277 / session / f8ac647c64a7e61a5d84e4ed9daa8c7c /远程WebDriver服务器的HTTP请求在60秒后执行超时 . ---> System.Net.WebException:请求已中止:操作已超时 . 在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)上的System.Net.HttpWebRequest.GetResponse()---内部异常堆栈跟踪结束---在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)在OpenQA上的OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令commandToExecute)中的OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令commandToExecute)中的OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2参数) . 位于Err.Program.Main(String [] args)的OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script,Object [] args)中的Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script,String commandName,Object [] args)在D:\ Temp \ Err \ Err \ Program.cs:第34行

这是代码:

static void Main(string[] args)
    {
        IWebDriver driver = new ChromeDriver();
        try
        {

            driver.Navigate().GoToUrl("http://www.google.com");
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            js.ExecuteScript("window.print();"); //this is the line that throws the error
        }
        catch (WebDriverException ex)
        {
            //just eat the error here since it's done opening the pdf viewer
        }


        //cannot execute the line below because the driver is dead in the water at this point - anything I try to do with it just times out...
        var q = driver.FindElement(By.XPath("descendant::input[@class = 'q']"));
    }