selenium c# keeping browser open permanently

2,141 views
Skip to first unread message

Szymon Roslowski

unread,
Apr 19, 2016, 5:21:15 AM4/19/16
to Selenium Users
Hi, 

I was wondering if I could open a browser, navigate to a certain page, fill in the form and then quit the application explicitly leaving the browser open for the user to take over.

Whatever I do the browser always closes when I destroy the driver. Sleep 99999 is absolutely not an option.

Basically I need to automatically fill in the form with data from a data source using automation rather than user typing (to avoid mistypes) but leave user the option to go over it and submit if everything is OK.

Fundamentally I thought Selenium would be a perfect tool for it but is it ?

Thanks.

Peter Gale

unread,
Apr 19, 2016, 5:25:57 AM4/19/16
to seleniu...@googlegroups.com
Check you code for where the reference to your browser object is terminated and make sure that the object doesn't get destroyed.

It is possible to leave the browser open after your code exists. If not it is a coding issue not a Selenium one.


Date: Tue, 19 Apr 2016 02:20:06 -0700
From: sajm...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] selenium c# keeping browser open permanently
--
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/36fed6a1-b53c-4706-bd8a-91f331ebe205%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Szymon Roslowski

unread,
Apr 19, 2016, 5:29:48 AM4/19/16
to Selenium Users
The Object will get destroyed as when the application finished filling in the form, it has done its job and therefore closes, destroying any and all objects created within.
But i want the browser to stay open after the application closes.

as to "it is possible to leave the browser open" could you demonstrate how ?

Thank you.

⇜Krishnan Mahadevan⇝

unread,
Apr 19, 2016, 5:31:38 AM4/19/16
to Selenium Users
As long as you aren't calling either driver.close() (or) driver.quit() the browser should stay open and not get closed.

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/

Szymon Roslowski

unread,
Apr 19, 2016, 5:35:30 AM4/19/16
to Selenium Users
That is the problem. It closes together with the application :

Here is an example app written in c#

The browser closes after the "John" line.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl("https://www.visa4uk.fco.gov.uk/account/register");
                var firstNameField = driver.FindElementById("FirstName");
                firstNameField.SendKeys("John");

                // At this stage Finished filling in the form so quit.
                // But leave the browser open !!!


            }
        }
    }
}

Szymon Roslowski

unread,
Apr 19, 2016, 5:59:59 AM4/19/16
to Selenium Users
This doesn't help either. Browser still closes when the application quits.

var options = new ChromeOptions {LeaveBrowserRunning = true};
using (var driver = new ChromeDriver(options))

Please Help.

Peter Gale

unread,
Apr 19, 2016, 6:57:43 AM4/19/16
to seleniu...@googlegroups.com
Perhaps you need to define the object at a higher level of scope.

I haven't notice a "LeaveBrowserRunning" setting for Chrome before, but you might want a solution that works for all browsers

Date: Tue, 19 Apr 2016 02:59:59 -0700
From: sajm...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: selenium c# keeping browser open permanently
--
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.

Szymon Roslowski

unread,
Apr 19, 2016, 11:56:14 AM4/19/16
to Selenium Users
Seems like something so trivial simply can't be done.

It's a waste having to ditch the idea of electricity for a broken switch, but seems like there is nothing else I can do.

Thank you all for replies.

Moving on....

Dmytro Zharii

unread,
Apr 19, 2016, 1:30:09 PM4/19/16
to Selenium Users
Hi Szymon, 

The browser closes automatically because you are initializing it inside the using block. 

            using (var driver = new ChromeDriver())
            {
            }


Just do not use using statement and the browser won't close (won't be disposed)

var driver = new ChromeDriver()

See also about "using":


-Dmytro
Reply all
Reply to author
Forward
0 new messages