Search code examples
c#google-chromeseleniumselenium-chromedriverchrome-web-driver

Chome opens for a split second then closes using selenium webdriver


I’m setting up chromedriver (win32) on visual studio using C#, I have firefox and it works great. I have downloaded the chromedriver.exe and set the PATH in windows to its location (C:...misc...\Selenium Webdriver\chromedriver) as the book “selenium recepies in C sharp” suggests. I am able to open up the driver via cmd and see the port. I have also used the NuGet package manager to get the chromewebdriver there. I have looked at this link with no success.

Chrome open for a split second and then closes.

My code.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;

namespace UnitTestProject1
{
    [TestClass]
    public class BrowserTest
    {
        [TestMethod]
        public void ChromeTest()
        {
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://www.google.com");
        }
    }
}

I’m willing to remove everything and start from scratch if I’ve botched the install somewhere along the way. Any help would be great.

EDIT: I have uninstalled and reinstalled chrome also.


Solution

  • using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Support.UI;
    using OpenQA.Selenium.Chrome;
    
    namespace UnitTestProject1
    {
        [TestClass]
        public class BrowserTest
        {
        string DRIVER_PATH = @"C:...misc...\Selenium Webdriver\chromedriver";
    
            [TestMethod]
            public void ChromeTest()
            {
                IWebDriver driver = new ChromeDriver(DRIVER_PATH);
                driver.Navigate().GoToUrl("http://www.google.com");
            }
        }
    }