Frage

I have tried using switching between windows using

    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.

Also tried with javascript executor method, but no use.

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

Please suggest if it's possible to do so.

War es hilfreich?

Lösung

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());

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top