Watir Code to "Close All Browser windows":
Option 1. Kill the process of browsers:
system("taskkill /t /f /im iexplore.exe")
Option 2.
require 'watir/close_all'
Watir::IE.close_all
This can be tweaked for all browser types like Chrome, Firefox, etc
On Thursday, December 31, 2009 7:12:40 AM UTC+5:30, Wesley Chen wrote:
>
> That's exactly as what Prajakta said, you can try the method provided
> below.
> def new_window
> # get a handle if one exists
> aa = Win32API.new("user32", "GetForegroundWindow",[] , 'L')
> hwnd = aa.call
> if (hwnd) # yes there is a popup
> return Watir::IE.attach(:hwnd, hwnd)
> else
> return nil
> end
> end
>
> $ie = Watir::IE.start("your_url")
> $ie.link("your_link").click
> if ie2 = new_window
> ie2.close
> end
>
> Thanks.
> Wesley Chen.
> For life, the easier, the better.
>
>
> On Wed, Dec 30, 2009 at 9:26 PM, Prajakta Jadhav
> <[email protected]<javascript:>
> > wrote:
>
>> If in case you are clicking on some link/image which in turn opens a new
>> browser window then u ll need to get the handle of that new window first.
>> Then u can execute browser.close on it.
>> U ll need to attach the new window to a new watir browser instance.
>> eg ->
>> ie2 = watir::IE.new
>> ie2.attach(:url, <url of new browser window>)
>> ie2.close
>>
>>
>>
>> On Wed, Dec 30, 2009 at 2:43 PM, Tester <[email protected]
>> <javascript:>>wrote:
>>
>>> i am running a watir script on a url. The script opens pdf documents
>>> in new windows. There are more that 100 pdf files on opening each in
>>> new window the window hangs and I am not able to run the entire
>>> script. Can some one help me out in this.
>>> Is there a method such as ie.close to close the new browser window
>>> getting opened from the main window in watir?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Watir General" group.
>>> To post to this group, send email to [email protected]<javascript:>
>>> Before posting, please read the following guidelines:
>>> http://wiki.openqa.org/display/WTR/Support
>>> To unsubscribe from this group, send email to
>>> [email protected] <javascript:>
>>> For more options, visit this group at
>>> http://groups.google.com/group/watir-general
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Watir General" group.
>> To post to this group, send email to [email protected]<javascript:>
>> Before posting, please read the following guidelines:
>> http://wiki.openqa.org/display/WTR/Support
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/watir-general
>>
>
>
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]