Skip to main content

Close Browser Windows in Scenario Editor

Close Browser Windows in Scenario Editor

Q:Use changingthis guidance when a Scenario Editor test opens a second browser window, tab, or popup and must return to the main application flow. Keep window -handling Iexplicit wantedso tothe closetest does not continue in the wrong context.

  1. Trigger the action that opens the new window onceor itstab.
  2. Wait existence had been confirmed but it wouldn’t let me, can’t seefor the closeexpected window, tab, or popup to be available.
  3. Validate or capture the needed content.
  4. Close the secondary window accessor and ifswitch I tryback to clickthe itoriginal ascontext.
  5. Validate part ofthat the recording nonext step isruns recorded

    A: The close window button is not part ofin the page,intended itpage.

is

Good partpractices

of
  • Use theclear browserstep application so it is impossible to record clicking on it.

    In javascript, there is a way (window.close();) to close a windownames that was opened with a window.open() javascript command but even this method will not work in some versions of Chrome, will not work in FireFox, and IE might prompt for confirmation.

    Ifidentify the window wasbeing nothandled.
  • Avoid openedrelying usingon windows.open()window thenorder thereif titles or URLs can be validated.
  • Capture output when popup behavior fails or is noblocked way to close it using javascript. But, you can try in your scriptby the below:

    Eval in Browser | "window.open('','_self').close();"


    Problem: What if Close window API is not working in the script?

    browser.

Solution:

As per research and latest spec of window.close()

Ordinary javascript cannot close windows willy-nilly. This is a security feature, introduced a while ago, to stop various malicious exploits and annoyances.

From the latest working spec for window.close():

The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

The corresponding browsing context A is script-closable.

The browsing context of the incumbent script is familiar with the browsing context A.

The browsing context of the incumbent script is allowed to navigate the browsing context A.

A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document.

This means, with one small exception, javascript must not be allowed to close a window that was not opened by that same javascript.

Example:


Problem: How to handle multiple windows in browser without closing any window?

Solutions: Using selectWindow – its not necessary to always use the title/name of window , we can also use href to uniquely identify the window. So in that case it might be easy to handle multiple windows for the flow without closing the window.


Last updated: JuneSeptember 26,9, 20232026

If you have any feedback on this topic, please contact us at documentation@appvance.ai