0
votes

I click on a link on a webpage in my application and a new window pops up (I'm using Internet Explorer 11, and not permitted to use any other browser).

The window is opened as an html page from the code: href=fileName.html.

However, none of the Robot framework Selenium2Library keywords will close the popped up window, such as Close Window, which according to the documentation, says, "Closes the currently open pop-up window". However, this command closes the main browser window and NOT the one that popped up.

I also tried using the variants of the Get Window command such as Get Window Titles or Get Window Identifiers, but it returned either the main browser window or no windows.

Is there a way to close popped up window?

Thanks

EDIT:

Here is the html link for the window:

<a title="Birth Proof Code More Information" id="uef-help0" href="birthProofHelp.html" target="_blank" rel="help" data-uefid="uef-li-hlp" data-modal-disable="true">More Info</a>

Here is the source code for the window:

!DOCTYPE HTML>
<html>
    <head>
        <title>Birth Proof</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>
        A - ALLEGED<br>
        B - BIRTH/BAPTISMAL CERTIFICATE (BEFORE THE AGE OF 5)  / PREFERRED BIRTH PROOF<br>
        C - DEFINITION OF 'CONVINCING EVIDENCE' MET<br>
        F -  PREVIOUSLY ESTABLISHED BY THE SSA<br>
        Q - ESTABLISHED BASED ON EVIDENCE OTHER THAN THAT COVERED UNDER CODES 'B' AND 'C'<br>
    </body>
</html>

I tried sleeping 60 seconds for the window to appear, and it still didn't work.

The window is really appearing. Like I said, Close Window closes the main browser window and NOT the one that popped up.

According to Robot documentation, Get Window Titles does this:

Returns the titles of ALL windows known to the current browser instance.

1
href=fileName.html by itself won't cause a new window to open up. Can you show the exact definition of the window. When you've tried close window, did you wait for a moment to get the window a chance to appear? Are you certain the window is appearing? if Get window titles and get window identifiers returns only the main window, it seems like this popup window isn't appearing. - Bryan Oakley
@BryanOakley Please see the edit in my OP - Kingamere

1 Answers

0
votes

java.awt.robot is an option if all else fails. Use the windows shortcut to close a window: ctrl+w.

EDIT: Adding how to focus the window first (I've been using this for a while and it's working for me, I think I originally got it from here, answer from @Avinash Jha):

    import com.sun.jna.Native;
    import com.sun.jna.platform.win32.WinDef.HWND;
    import com.sun.jna.win32.W32APIOptions;

    ...

    public interface User32 extends W32APIOptions {
        User32 instance = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);
        boolean ShowWindow(HWND hWnd, int nCmdShow);
        boolean SetForegroundWindow(HWND hWnd);
        HWND FindWindow(String title);
        int SW_SHOW = 1;
    }

    ...

    User32 user32 = User32.instance;
    HWND hWnd = user32.FindWindow("window title");
    user32.ShowWindow(hWnd, User32.SW_SHOW);
    user32.SetForegroundWindow(hWnd);

Then the robot part should be something like:

import java.awt.*;
import static java.awt.event.KeyEvent.*;

...

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_W);
robot.keyRelease(KeyEvent.VK_W);
robot.keyRelease(KeyEvent.VK_CONTROL);