((JavascriptExecutor)driver).executescript("window.print=function(){};");
但是,如果您的目标是测试是否调用了打印,则:
// get the print buttonWebElement print_button = driver.findElement(By.cssSelector("..."));// click on the print button and wait for print to be calleddriver.manage().timeouts().setscriptTimeout(20, TimeUnit.SECONDS);((JavascriptExecutor)driver).executeAsyncscript( "var callback = arguments[1];" + "window.print = function(){callback();};" + "arguments[0].click();" , print_button);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)