0

Trying to print PDF through iframe

WebDriverWait wait_iframe = new WebDriverWait(driver, 20000);
wait_iframe.until(ExpectedConditions.visibilityOfElementLocated((By.id("printpdf"))));

Expected result is bill pdf print should be visible on the screen, but actual output it is throwing an error message i.e Error: Permission denied to access property "print"

Browser code:

var urlBase = url + '?title=' + escape(data.url);
var iframe = '<iframe id="printpdf" src="' + urlBase + '" frameborder="0" width="100%" height="100%"></iframe>';
$("#loadPdf").empty().html(iframe);
$('#printpdf').on("load", function() {
    printPDF();
});

function printPDF() {
    var frame = document.getElementById("printpdf");
    frame.focus();
    frame.contentWindow.print();
}
Kafels
  • 3,864
  • 1
  • 15
  • 32
Jyothi
  • 13
  • 4
  • Hi Kafel, not having any link related to pdf,trying to print final bill in billing application,developers code:: var urlBase = url + '?title=' + escape(data.url); var iframe = ''; $("#loadPdf").empty().html(iframe); $('#printpdf').on("load", function () { printPDF(); }); function printPDF() { var frame = document.getElementById("printpdf"); frame.focus(); frame.contentWindow.print(); } – Jyothi May 15 '19 at 04:49
  • Trying to write selenium code for printing final bill, but the related iframe is not detected in firepath , the above mentioned code is developers side code , by taking the frameid and while running its throwing an error: Permission denied to access property "print" – Jyothi May 15 '19 at 04:54
  • Well, probably you've with this same problem [jQuery/JavaScript: accessing contents of an iframe](https://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – Kafels May 15 '19 at 13:12
  • Hi kafel , the link is showing developers side code, the thing i need is how to print final bill using jasper report in pdf format, how to access the code in selenium – Jyothi May 16 '19 at 04:47

0 Answers0