Forum Discussion

sirping's avatar
Occasional Contributor
3 years ago

Close Browser before Test

I need a Python script that closes Chrome if it is open before a Test


Currently I have a function looking like this


def closeBrowserIfOpen():
    p = Sys.WaitBrowser("chrome", 0)
    if (p.Exists):
        Log.Message("Browser Closed")



But even though I have 0 as the timeout parameter, the script still waits for the Browser for about 3 seconds. How can I get rid of this delay completely? I just want it to execute instantly. In the docu it says:



The number of milliseconds to wait until the browser process becomes available. If Timeout is 0, the method returns immediately. If Timeout is -1, the wait time is specified by the Auto-wait timeout project setting.


But this is not true, since there is still a timeout of about 3 seconds while executing this code.


Btw: My Auto-wait timout is 40000.

3 Replies

  • Hi sirping!


    Looks like your 'p' variable is using a Wait method, which will take a few seconds to find the process. 


    You can simply swap this out with the updated code below. This will be the fastest way to find and close Chrome.

    p = Sys.Process("Chrome")


    I hope this helps!

  • sirping's avatar
    Occasional Contributor


    I want to close the browser, if it is open. But if it is not open I want to do nothing. This code would fail if the Chrome Browser would not be open