gpt4 book ai didi

c# - 在 Windows 主机中运行 selenium 时出现错误预期的浏览器二进制位置

转载 作者:行者123 更新时间:2023-12-04 17:43:11 24 4
gpt4 key购买 nike

这个示例工作:
获取 google 的文本并显示在主页示例 asp.net 中
在 Windows 主机中测试 Selenium 的正确工作。

我想在 Windows 托管 plesk 中运行 selenium。

我的错误:

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

}



}

最佳答案

尝试通过 options变量变成new FirefoxDriver()的参数.它对我来说是这样的:

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))
{
//...

实际上,我看到一个使用 options 的注释变量对象,您在使用它时是否有任何错误?

关于c# - 在 Windows 主机中运行 selenium 时出现错误预期的浏览器二进制位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53496010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com