Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Expected browser binary location when run selenium in windows hosting

this sample work: get text of google and show in home page sample asp.net test for correct work selenium in windows host.

i want to run selenium in windows hosting plesk.

error for me:

Server Error in '/' Application.

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)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: 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)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:

[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)]
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) +1059
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) +125
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) +235
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) +54
OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options) +81 WebDriverwithwebapp._Default.Page_Load(Object sender, EventArgs e) +178
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678

   protected void Page_Load(object sender, EventArgs e)
    {

        FirefoxOptions options = new FirefoxOptions();
        options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine

       // WebDriver driver = new FirefoxDriver(options);

        using (var FireFoxPage = new FirefoxDriver())
        {
            //_driver = new FireFoxDriver();
            _driver.Manage().Window.Maximize();
            _driver.SwitchTo().Window(_driver.CurrentWindowHandle);
            _driver.Manage().Cookies.DeleteAllCookies();
            // _driver.Manage().Timeouts().ImplicitWait(TimeSpan.FromSeconds(3));

            _driver.Navigate().GoToUrl("https://google.com/");

            _driver.FindElement(By.Id(Button_ID)).Click();


          IwebElement  Element1 = _driver.FindElement(By.XPath("/html/body/main/div/div/div[3]/span"));
            ksc = Element1.Text.ToString();

            Label1.Text = ksc.ToString();

            _driver.Quit();
            Process[] geckodriverProcesses = Process.GetProcessesByName("geckodriver");
            foreach (var geckodriver in geckodriverProcesses)
            {
                geckodriver.Kill();
            }

        }



    }
like image 408
MasoudMadakto Avatar asked Apr 06 '26 17:04

MasoudMadakto


1 Answers

Try passing the options variable into the parameters of new FirefoxDriver(). It worked for me like this:

FirefoxOptions options = new FirefoxOptions();
    options.BrowserExecutableLocation = ("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine

   // WebDriver driver = new FirefoxDriver(options);

    using (var FireFoxPage = new FirefoxDriver(options))
    {
   //...

Actually, I see a commented variable using the options object, did you have any errors using it instead?

like image 163
Julian B. Avatar answered Apr 09 '26 07:04

Julian B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!