Selenium VBA-退出子而不关闭浏览器窗口 [英] Selenium VBA - exit sub without close browser window
问题描述
如何在不关闭浏览器窗口的情况下退出子(宏)?代码完成后,Chrome浏览器会自动关闭.
How can I exit a sub (macro) without close browser window? When code finish Chrome browser automatically close.
例如我有
Sub test()
Dim driver As New ChromeDriver
driver.Get "http://www.google.com"
End Sub
谢谢!
推荐答案
一旦驱动程序的变量超出范围,浏览器将自动释放.有关更多信息,请邀请您查看官方文档: https://support.microsoft.com/en-gb/kb/141693
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
要使用上述示例获取最新的日期,请执行以下操作: https://github.com/florentbr/SeleniumBasic/releases/latest
To get the latest version in date working with the above example: https://github.com/florentbr/SeleniumBasic/releases/latest
这篇关于Selenium VBA-退出子而不关闭浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!