Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda