1

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
  • also looking for solution. any update?
    – H. Motsu
    Mar 25 at 17:13

1 Answer 1

1

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.

2
  • 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();
    – Liza
    Jul 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
    – Liza
    Jul 17, 2020 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.