I need to save a page as a PDF but I'm having issues. I'm using ChromeDriver and just using google as an example (since my app requires logging in) I navigate to the page (google.com). Then execute window.print() in javascript to get the print window to come up. Chrome opens the print preview page and I get the src of the iframe showing the pdf so I can pull the pdf from the url.
My issue is that at the point I execute the javascript it opens the print preview but execution stops there. It's like ChromeDriver is waiting for the page to say it's finished but the message never comes so I recieve a WebDriverException saying it timed out.
The weird thing is this used to work up until yesterday when I got a bunch of windows updates and updated a bunch of programs including Chrome.
So does anyone have any idea how to make this work again?
I'm using Google Chrome Version 62.0.3202.94 (Official Build) (64-bit) OS is Windows 10 ChromeDriver version is 2.33.0 Selenium WebDriver is 3.7.0
Here's the error:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:12277/session/f8ac647c64a7e61a5d84e4ed9daa8c7c/execute timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out. at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) --- End of inner exception stack trace --- at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args) at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object[] args) at Err.Program.Main(String[] args) in D:\Temp\Err\Err\Program.cs:line 34
Here's the code:
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']"));
}