This error message...
System.InvalidOperationException: 'Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line (SessionNotCreated)'
...implies that the GeckoDriver was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session.
Possibly firefox browser is installed at a non-conventional location, hence GeckoDriver is unable to access the firefox
binary.
Solution
As a solution pass the absolute location of the firefox.exe
binary through the BrowserExecutableLocation
argument of FirefoxOptions
as follows:
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //location where Firefox is installed
WebDriver driver = new FirefoxDriver(options);