Selenium VBA - exit sub without close browser window

后端 未结 1 1617
攒了一身酷
攒了一身酷 2021-01-14 19:07

How can I exit a sub (macro) without close browser window? When code finish Chrome browser automatically close.

For example I have

Sub test()
Dim dri         


        
相关标签:
1条回答
  • 2021-01-14 19:48

    The browser is automatically disposed once the variable of the driver is out of scope. For further information, I invite you to have a look at the official documentation: https://support.microsoft.com/en-gb/kb/141693

    So, to avoid quitting the browser, you need to set the instance of the driver on a global variable:

    Private Assert As New Assert
    Private driver As New Selenium.FirefoxDriver
    
    Sub ProcMain()
        driver.Get "http://stackoverflow.com"
        Call ClickLogo
    End Sub
    
    Sub QuitDriver()
        driver.Quit
    End Sub
    
    Sub ClickLogo()
        driver.FindElementByCss("#hlogo").Click
    End Sub
    

    To get the latest version in date working with the above example: https://github.com/florentbr/SeleniumBasic/releases/latest

    0 讨论(0)
提交回复
热议问题