# "Do you want to close this Window?" Popup woes

**URL:** <https://www.ruby-forum.com/t/do-you-want-to-close-this-window-popup-woes/66187>\
**Category:** Ruby\
**Created:** [August 23, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/do-you-want-to-close-this-window-popup-woes/66187 "2006-08-23T21:41:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 23, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/do-you-want-to-close-this-window-popup-woes/66187/1 "2006-08-23T21:41:21Z")

</div>

Hello,

I am new at this and using a co-worker app to record test scripts in  
Ruby. Its called Watir. The script I have logs into a test account for  
online banking. It then hits the logoff URL which sends you to a page  
with a “Close Window” or “Login” button. The close button does this:  
javascript:doClose()

Everything works great except the close window part. When you click the  
close button a Window IE Popup comes up saying a program is attempting  
to close the window. Do you want to close it? Yes or No.

How in the heck to I go about closing this window with the script. Here  
is what I have, though keep i mind I have ommitted the account  
information.

require ‘watir’  
include Watir  
require ‘test/unit’  
class TC\_recorded \< Test::Unit::TestCase  
def test\_recorded  
ie = IE.new  
ie.goto(‘[http://www.capitalonebank.com/](http://www.capitalonebank.com/)’)  
ie.text\_field(:name, ‘txtUserID’).set(‘user id here’)  
ie.text\_field(:name, ‘txtPassword’).set(‘password here’)  
ie.button(:name, ‘login’).click  
ie.text\_field(:id, ‘txtSecurityAnswer1’).set(‘answer here’)  
ie.button(:id, ‘btnLogIn’).click  
ie.goto(‘[https://onlinebanking.capitalone.com/CAPITALONE/Logout.aspx](https://onlinebanking.capitalone.com/CAPITALONE/Logout.aspx)’)  
ie.goto(‘javascript:top.window.close()’)  
end  
end

This is driving me crazy so any help would be great! Even if I could  
somehow click the X in the right corner with code, that would be a way  
to avoid the question in the first place! But I dont know how.

David

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 23, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/do-you-want-to-close-this-window-popup-woes/66187/2 "2006-08-23T22:06:30Z")

</div>

On 8/23/06, David N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to close the window. Do you want to close it? Yes or No.  
> ie = IE.new
> 
> This is driving me crazy so any help would be great! Even if I could  
> somehow click the X in the right corner with code, that would be a way  
> to avoid the question in the first place! But I dont know how.
> 
> David

Hi,

this is AutoIT3 script that I use to get rid of those “New Hardware  
Found” windows.  
Save it as e.g. close\_popup.au3, download autoit and compile to exe.  
It will run in the background waiting for specified windows and  
closing them. You can stop it by using /QUIT.

Just change ‘Found New Hardware Wizard’ to the title of your window,  
and ‘Welcome’ to any text of the popup.

You can change the name of the script window (‘KillHWiz’) but it’s not  
neccessary.

There is also a auto it dll that you can use through Win32API or  
ruby/dl.

HTH,  
J.

----8\<--------------------

If $CmdLine[0] = 1 and $CmdLine[1] = ‘/QUIT’ Then  
WinClose(‘KillHWiz’)  
Else  
AutoItWinSetTitle(‘KillHWiz’)

```
While 1=1
	WinWait ( 'Found New Hardware Wizard', 'Welcome' )
	WinClose ( 'Found New Hardware Wizard', 'Welcome' )
WEnd

```

EndIf

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 24, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/do-you-want-to-close-this-window-popup-woes/66187/3 "2006-08-24T16:03:47Z")

</div>

David N. wrote:

> How in the heck to I go about closing this window with the script. Here  
> is what I have, though keep i mind I have ommitted the account  
> information.

This is a security thing in JavaScript. JavaScript is not allowed to  
close a window unless JavaScript was the one that opened the window in  
the first place (via something like, “javascript:  
top.window.open(‘mypopup.html’);”. You wouldn’t want JS to be able to  
indiscriminately close your browser on you.

It seems sensible that you’d be able to close IE via watir (not using  
JavaScript), since that’s how you opened it in the first place. But I  
don’t know anything about watir.
