Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Problem closing a child window using Javascript in web automation

I'm trying to automate a browser process using Selenium WebDriver.

The web site generates a series of downloadable files with a link button for each. Clicking on the link button opens up a new browser window in which the file is downloaded. But the new browser window is not coded to close.

I have located the JavaScript/jQuery function OpenWindowUrl in chrome's web dev tool that opens up the new browser window, and the gist of the function is shown below.

As you can see, the function calls another function GetRootWin to open up the new browser window and download the file, then forces the new browser window into the foreground. I wish it had a few more lines to close it after 3 seconds or so.

Since the variable wnd which is the handle of the new browser window is scoped inside the function definition, I'm not able to use it in my automation to close the browser window like wnd.close();, because wnd is undefined outside of the function.

Although my automation process works fine without closing the child windows, potentially it will leave me over 200 child windows open, not a good idea.

Is there a way to override this OpenWindowUrl function such that my new OpenWindowUrl will be called by the website instead? If yes, I can run my new snippet for OpenWindowUrl using Selenium's IJavaScriptExecutor before downloading the files. Or is there a way to inject wnd.close(); into the OpenWindowUrl function?

$.extend(Namespace('NS'), {
 OpenWindowUrl: function (url, winName, parameters) {
        ... ...
        var wnd = NS.GetRootWin().open(url, winName, parameters);
        // Force the window into the foreground
        setTimeout(function () {
            wnd.focus();
        }, 500);
    },
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda