Forum Discussion

shaifali_pandya's avatar
shaifali_pandya
Occasional Contributor
12 years ago

How to ensure that the Browser has been closed


 



Example code under help topic "Checking if the Browser Is Running From Scripts"

function Check()

{

  if (Aliases.browser.Exists)

    Aliases.browser.BrowserWindow.Close();



  Browsers.Item(btIExplorer).Run("http://smartbear.com");

}



BUT as we do not plan to use NameMapping, our code is as follows



Line1  if (Sys.Browser(myBrowser).Exists)

Line2    Sys.Browser(myBrowser).Close();



Line3  Browsers.Item(myBrowser).Run(mySiteURL);



above code results in "The browser is already running." on Line3 in case Line2 was executed.


  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor


    The examples in this help topic could be useful to wait while the browser still exists since there is probably a slight delay.



    Checking if the Browser Is Running From Scripts


  • shaifali_pandya's avatar
    shaifali_pandya
    Occasional Contributor
    Can you please explain, what is your suggestion. The code in my post is from the help topic you have mentioned.
  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor


    Sorry the link I was referring to was missing when I pasted into my reply

    Checking if the Browser Is Running From Scripts

    http://support.smartbear.com/viewarticle/33274/#Scripts



    The example there is slightly different and uses while statement and WaitBrowser method rather than if statement. Can you try this?



    function Check()

     {

      while (Sys.WaitBrowser().Exists)

      // if (Sys.WaitBrowser().Exists)

        Sys.WaitBrowser().Close();



      Browsers.Item(btIExplorer).Run("http://smartbear.com");

     }


  • shaifali_pandya's avatar
    shaifali_pandya
    Occasional Contributor
    Issue is not closing the browser, BUT opening immediately after closing. Example code has the while loop to close the browser, how can it resolve the issue of opening immediately (maybe the open gets executed while it is being closed)
  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor


    I also thought that next event to launch the browser was executed while the previous browser process was still closing.



    However it might just be a problem specifying the browser.



    On line 1 and 2 using the Browser method the browser can be specified by the process name "iexplore" etc.

    http://support.smartbear.com/viewarticle/29898/

    On line 3 using the Browsers Object item property a browser can be specified via built-in constant, by the process name or by index within the collection.

    http://support.smartbear.com/viewarticle/33200/



    If myBrowser = a constant like btIExplorer it won't work on those first 2 lines.


  • ArmandsBruns's avatar
    ArmandsBruns
    Frequent Contributor
    Hi Shef Deshmukh,



    Try this:



    =======

    process = Sys.FindAllChildren("ProcessName","your_process")

      If UBound(your_process)>=0 Then

      Do  

        For i = UBound(your_process) to LBound(your_process) Step -1

          Log.Message(i)

          your_process(i).Terminate

          aqUtils.Delay(3000)   

        Next

      Loop While your_process.Exists = False  

      End If

    =======



    Best regards

    Armands