尝试通过iframe打印PDF
WebDriverWait wait_iframe = new WebDriverWait(driver, 20000);
wait_iframe.until(ExpectedConditions.visibilityOfElementLocated((By.id("printpdf"))));
预期结果是账单pdf打印应该在屏幕上可见,但实际输出会引发错误消息,即错误:拒绝访问属性“ print”的权限
浏览器代码:
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();
}