VBA + Selenium keep browser open after test

2,555 views
Skip to first unread message

hunsnowboarder02

unread,
Dec 18, 2015, 3:19:18 PM12/18/15
to Selenium Users
Hi there!

I have a very frustrating problem. Each time I run the test in VBA, after the test is run the webpage is closed. However I do not have quit or exit command.

Could someone please let me know how to leave the webpage as it is, without closing it?

Thank you in advance!

My code:

Sub Toto_Szerencsejatek()

 
Dim my_url As String
 
Dim driver As New Selenium.WebDriver

  my_url
= "http://www.szerencsejatek.hu/toto"

  driver
.Start "firefox", my_url
 
driver.Get my_url

End Sub



PeterJeffreyGale .

unread,
Dec 18, 2015, 3:38:00 PM12/18/15
to seleniu...@googlegroups.com

It's possibly VBA's garbage collection routine killing the driver process as your program finishes.

Whst happens if you set the driver object to null/nothing (to break the link to the open browser) at the end of your method?

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
> To post to this group, send email to seleniu...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b74a2059-c7e7-4214-8853-5e956addb38c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

hunsnowboarder02

unread,
Dec 19, 2015, 7:51:39 AM12/19/15
to Selenium Users
Thank you for your reply.

Actually happens the same, window closes.

David

unread,
Dec 19, 2015, 1:52:27 PM12/19/15
to Selenium Users
Peter's probably right about the garbage collection. From your code it looks like you create an instance of the driver right in the function/subroutine. So it's only in scope in there, so once the subroutine exits, the driver does not exist, which is same as equating to terminating the driver instance (and hence the browser window).

I'm not familiar with VBA, but is there somewhere else you can place the driver instance/instantiation in a global scope, and then this subroutine simply gets access to the driver instance as a global variable or from having the reference to the driver instance variable passed into the subroutine as an argument? For standard VB/VBScript, this is trivial to do. But for VBA with apps like Excel, Word, I'm not familiar with how you define global and app startup/teardown scopes for VBA code.

hunsnowboarder02

unread,
Dec 20, 2015, 9:29:59 AM12/20/15
to Selenium Users
This makes sense absolutely. Will try it and give a feedback on it.

Krishnan Mahadevan

unread,
Dec 20, 2015, 8:16:29 PM12/20/15
to Selenium Users
David/Peter

I dont seem to see this behavior with java. So kind of curious: is this garbage collection behavior specific to vba ?

Do you know if the vba implementation of selenium has some kind of destructors which gracefully quit the browser when the webdriver object goes out of memory ?

Thanks & regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

PeterJeffreyGale

unread,
Dec 21, 2015, 3:50:10 AM12/21/15
to Selenium Users
I use Java for WebDriver, but VBA for other work.

I've not seen this behaviour, in Java, but that's not to say we couldn't replicate it if we knew what caused it.

I don't see that there can be any fundamental differences in the implementation, which and I don't see that the VBA implementation of webdriver itself will handle any garbage collection, though in the absence of an explicit call to close the browser, this seemed a likely cause, as I recall that garbage collection can work differently in different languages. 

PeterJeffreyGale

unread,
Dec 21, 2015, 3:51:47 AM12/21/15
to Selenium Users
Could be a question for the guys writing the VBA implementation itself, though I'd recommend the op switch to java for access to wider support and documention.
Reply all
Reply to author
Forward
0 new messages