Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!