Ask a Question

Script To Automatically Close 'Active' Window

Occasional Contributor

Script To Automatically Close 'Active' Window

Hi all,


I have another question that may sound silly. The application I am testing will open patient records in 2 different ways, half will be maximised view and the other half is a minimised view. Both views have a 'Minimise', 'Maximise' and 'Close' button. 


My issue is when setting up the automated tests I run into problems as sometimes the window will be maximised and others minimised so when I go to close the window the test case will fail as it is looking for the 'Close' function to be in a specific spot which it is not.


What I was wanting to do it run a script to close the window regardless of where it is place on the screen. I figured I could do this using the 'Run Code Snippet' feature but unfortunately, I am not a coder and the developers we use are through an external company. I tried googling and searching on this forum to see if there was a snipit of code for a Microsoft.Net program to execute the close button but I am not finding anything too helpful.


I was hoping someone might be able to point me to some information that may help me, If more information is needed or screenshots are needed please let me know.


Thank you and I hope my query makes sense. 

Champion Level 2



I assume that you are working with a desktop application...

Usually, desktop windows have .Close() method that closes them. Check this with Object Browser.

Alternatively, you may send keys combination to the window that closes it. Usually this is Ctrl-F4 or Ctrl-W.

Both approaches should close the target window without the necessity to click its Close button.


  /Alex [Community Champion]
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
SmartBear Alumni (Retired)

Thanks for your help, Alex!


@helpdesk, is this what you were looking for?

Tanya Yatskovskaya
SmartBear Community and Education Manager

Occasional Contributor



Maybe you can use this code here choose the languange in which your project is and instead run code snippet use run script routine.

Hope this helps.



i'm sorry, didn't understand correctly, you want to close a window which is part of your application not another app that is called from the first one. My bad.

Occasional Contributor

Thank you very much - Control F4 closes any active window within the application.


I appreciate the response 🙂

Showing results for 
Search instead for 
Did you mean: