When I click on Print link in chrome browser , a pop is opened which shows it as a PDF file and then on the right side there are printing options with save , print etc buttons . Now when I click the print button which is on Browser , this pop up opens and the execution just pauses and I am stuck .
1 Answer
This would help you. I have tried a sample run with W3 school print example.
WebDriver driver=new ChromeDriver();
System.setProperty("webdriver.chrome.driver","driverpath");
driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_print");
driver.switchTo().frame("iframeResult");
//js executor to prevent print function
((JavascriptExecutor)driver).executeScript("window.print=function(){};");
driver.findElement(By.xpath("//button[@onclick=\"window.print()\"]")).click();
This will not make the print action so that print dialog box will not be popped up.
-
hi , Thanks for the answer . i tried the above like this below but executions pauses after click . detailsPage.getAlertDetailsPrint1().click(); getDriver().switchTo().frame("iframeResult"); // js executor to prevent print function ((JavascriptExecutor) getDriver()).executeScript("window.print=function(){};"); getDriver().findElementByXPath(("//button[@onclick=\"window.print()\"]")).click();– LizaJul 17, 2020 at 20:52
-
i need to click print button on applictaion page , which makes this pop up appear and i need to verify it this pop up appears and then click cancel– LizaJul 17, 2020 at 21:03