3
votes

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();
            }

        }



    }
1
The error indicates that the path to the firefox executable is wrong. Have you checked that it is correct? Is Firefox also installed on the server where you want to execute the code? - sisve
Run to windows hosting plesk. - MasoudMadakto
no solution?!!!!! unknown error: cannot find Chrome binary (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.14393 x86_64) - MasoudMadakto

1 Answers

1
votes

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?