2

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.

Dodo
  • 93
  • 2
  • 10
  • 1
    My guess is that Selenium closes the browser at the end of a test. Try putting in Selenium.WaitForPageToLoad("3000"); – mowwwalker Oct 21 '15 at 16:52
  • When I replace Chromedriver with Firefoxdriver it works fine and leaves a firefox window open. I tried `Thread.Sleep(100000);` as you suggested to let it wait but no luck. It still immediately crashes. – Dodo Oct 21 '15 at 18:55
  • If it is crashing, debug it... what error is it throwing? – JeffC Oct 21 '15 at 20:13
  • An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code Additional information: unknown error: unrecognized Blink revision: 07d51ee3ea74c918d7eb65938af89e443bf95a3a – Dodo Oct 21 '15 at 20:33
  • That's the error I get from `IWebDriver driver = new ChromeDriver();` I'm also getting a command prompt popup now saying `Starting ChromeDriver on port 51244 Only local connections are allowed`. Any help would be great with this, can't make sense of it. – Dodo Oct 21 '15 at 20:37
  • Maybe this could help? http://stackoverflow.com/questions/32792739/selenium-unexpectedly-having-issues – mowwwalker Oct 21 '15 at 22:27
  • Hi, thanks for your reply but I was able to follow the answer @L.Bar gave below and that worked for me. Thank you though! – Dodo Oct 22 '15 at 08:14

2 Answers2

1
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");
        }
    }
}
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
  • This fixed it. Thanks a million! It's always something simple :) – Dodo Oct 22 '15 at 08:13
  • What was the issue resolution? I am having the same issue. I added the source which is `Environment.CurrentDirectory` and it still closes. – Si8 May 03 '19 at 14:17
0

I am new to selenium. As per tutorial I installed Web Driver for Google Chrome i.e WebDriverChromedriver. On running the sample program I got the same issue. Then I installed "Selenium.Chrome.WebDriver" package from Nugetpackage. And my program got executed successfully.

enter image description here

S.Spieker
  • 7,005
  • 8
  • 44
  • 50