如何使用Chrome网络驱动程序测试Chrome浏览器的打印预览? [英] How to Test Print-preview of Chrome browser using Chrome webdriver?

查看:653
本文介绍了如何使用Chrome网络驱动程序测试Chrome浏览器的打印预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用

    String winHandleBefore = driver.getWindowHandle();
    <code to print>
    for (String winHandle : driver.getWindowHandles())
         driver.switchTo().window(winHandle);
    driver.findElement(By.className("cancel")).click();
    driver.switchTo().window(winHandleBefore);

这会在打开打印预览页面后挂断我的测试用例执行.

This hangs my test case execution after it opens the print preview page.

也尝试过使用javascript executor方法,但是没有用.

Also tried with javascript executor method, but no use.

   JavascriptExecutor jse = (JavascriptExecutor) driver;
   jse.executeScript("window.close()", "");

请建议是否有可能.

推荐答案

我找到了我问题的答案.我在下面的代码段中使用过.

I have found the answer to my question. I used below code snippet.

 //Create a Region for Desktop Screen
 ScreenRegion s = new DesktopScreenRegion();
 //Find target with below Image in Desktop Screen
 Target target = new ImageTarget(new File("Image.png"));
 ScreenRegion r = s.find(target);
 // Create a mouse object
 Mouse mouse = new DesktopMouse();
 // Use the mouse object to click on the center of the target region
 mouse.click(r.getCenter());

借助此代码片段,您将能够找到printcancel并进行鼠标单击事件并继续进行硒测试.可以使用sikuli API

With the help of this snippet you would able to find the print or cancel and do the mouse click event and proceed with selenium tests. This was possible using sikuli API

这篇关于如何使用Chrome网络驱动程序测试Chrome浏览器的打印预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆