0

I'm getting NullReferenceException when I'm trying use chromeDriver.Quit() in the end of my test . My suspicions is because i using SwitchToWindow function that looks like this :

public void SwitchToWindow(Expression<Func<IWebDriver, bool>> predicateExp)
{
    var predicate = predicateExp.Compile();
    foreach (var handle in chromeDriver.WindowHandles)
    {
        chromeDriver.SwitchTo().Window(handle);
        if (predicate(chromeDriver))
        {
            return;
        }
    }

    throw new ArgumentException(
                string.Format("Unable to find window with condition: '{0}'", 
                               predicateExp.Body));
}

In the middle of my test , I'm going to another window and then back to the first one and then I'm trying to close all the windows . but for some reason chromeDriver.Quit() not working for me and i get this error. My chrome driver looks like this in the beginning of all my test

  private IWebDriver chromeDriver;

public void OpenAdAssistantPage(out ChromeOptions options, out ChromeDriverService service,
        out DesiredCapabilities capabilities, out IWebDriver chromeDriver)
    {
        log.Info("end to end test ");
        options = new ChromeOptions();
        options.AddArgument("--test-type");
        options.AddArgument("--ignore-certifcate-errors");
        options.AddArgument("--enable-logging");
        options.AddArgument("--logging-level=3");
        options.AddArgument("--log-path=c:\\temp\\chromedriver.log");
        options.AddArgument("-incognito");

        service = ChromeDriverService.CreateDefaultService();
        service.LogPath = "c:\\temp\\chromedriver.log";
        service.EnableVerboseLogging = true;

        capabilities = DesiredCapabilities.Chrome();
        capabilities.SetCapability(ChromeOptions.Capability, options);

        chromeDriver = new ChromeDriver(service, options);
        //  chromeDriver.Manage().Window.Maximize();
        chromeDriver.Navigate().GoToUrl("my_url");

}

what could be the problem ?

Daria Shalimov
  • 131
  • 1
  • 1
  • 8

0 Answers0