How to handle a dialogue box

hello,

I have a test scenario in which i have to click on a print icon in a web page. A new window will appear for printing. However I dont want to perform actual printing, i want to close the newly opened print window. After closing only I will be able to work on the initial page. I have tried switch to window index, close window index, but its not closing the print page. I have tried Alert option also, but that too didnt work. Pages are as showed below.

Main page

print page

image

Here are the codes I tried:

2019-03-11 16:30:27.293 e[39mDEBUGe[0;39m e[36mtestcase.Test case 11,12,13,14,15,16,17 -e[0;39m e[39m23: switchToWindowIndex(1)e[0;39m
2019-03-11 16:30:27.350 e[39mDEBUGe[0;39m e[36mtestcase.Test case 11,12,13,14,15,16,17 -e[0;39m e[39m24: closeWindowIndex(1)e[0;39m
2019-03-11 16:30:48.787 e[1;31mERRORe[0;39m e[36mc.k.k.core.keyword.internal.KeywordMain -e[0;39m e[31m❌ Unable to close window with index 1e[0;39m
2019-03-11 16:30:48.797 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ closeWindowIndex(1) FAILED.e[0;39m
e[31mReason:

Please help.

give katalon recorder a try and look what the utility records as steps. maybe this helps.

Hello @masdesign,

I gave it a try, but nothing recorded for closing the dialogue box. It just captured till clicking the print button, after that I closed the newly opened print window, but that step havent recorded.

image

Any thoughts?

hello,

I found a solution. I have tried the Robot.key press after importing the following classes.

import java.awt.Robot;
import java.awt.event.KeyEvent;

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_ALT)
robot.keyPress(KeyEvent.VK_F4)
// Function+F4 is now pressed

robot.keyRelease(KeyEvent.VK_F4)
robot.keyRelease(KeyEvent.VK_ALT)
// Function+F4 now released

So by pressing the Alt+F4, the print window got closed. Thanks!!

3 Likes

That’s a nice “hack” with ALT + F4

I share this with my test automaters as well.

Thanks