Selenium VBA - 退出sub而没有关闭浏览器窗口

时间:2015-11-22 16:36:23

标签: excel-vba selenium vba excel

如何在不关闭浏览器窗口的情况下退出子(宏)?代码完成后,Chrome浏览器会自动关闭。

例如我有

Sub test()
Dim driver As New ChromeDriver
driver.Get "http://www.google.com"
End Sub

谢谢!

1 个答案:

答案 0 :(得分:2)

一旦驱动程序的变量超出范围,浏览器就会自动处理。 有关详细信息,我邀请您查看官方文档: https://support.microsoft.com/en-gb/kb/141693

因此,为了避免退出浏览器,您需要在全局变量上设置驱动程序的实例:

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

要使用上面的示例获取最新版本的日期: https://github.com/florentbr/SeleniumBasic/releases/latest

相关问题