错误在windows宿主中运行selenium时需要浏览器二进制位置



此示例工作:获取谷歌的文本并显示在主页示例asp.net中在windows主机中测试硒的正确工作。

我想在托管plesk的windows中运行selenium。

对我来说错误:

"/"应用程序中的服务器错误。

预期的浏览器二进制位置,但在默认情况下找不到二进制location,没有提供'moz:ffirefoxOptions.binary'功能,也没有命令行上设置的二进制标志(SessionNotCreated(

描述:在执行期间发生未处理的异常当前web请求。请查看堆栈跟踪以了解更多信息有关错误的信息以及错误在代码中的来源。

异常详细信息:System.InvalidOperationException:应为浏览器二进制位置,但无法在默认位置找到二进制,否提供了"moz:ffirefoxOptions.binary"功能,但没有二进制标志在命令行上设置(SessionNotCreated(

来源错误:

在执行期间生成了未处理的异常当前web请求。关于可以使用下面的异常堆栈跟踪来识别异常。堆栈跟踪:

InvalidOperationException:需要浏览器二进制位置,但无法在默认位置找到二进制文件,否提供了"moz:ffirefoxOptions.binary"功能,但没有二进制标志在命令行上设置(SessionNotCreated(]
OpenQA.Senium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应errorResponse(+1059
OpenQA.Selemenium.RemoteWebDriver.Execute(字符串driverCommandToExecute,Dictionary `2 parameters(+125
OpenQA.Eselenium.Remote.RemoteWebDriver.StartSession(ICapabilitiesdesiredCabilities(+235
OpenQA.Senium.RemoteWebDriver.ctor(ICommandExecutorcommandExecutor,ICapabilities desiredCabilities(+54
OpenQA.Eselenium.Firefox.FirefoxDriver.ctor(FirefoxOptions选项(+81带有网络应用程序的网络驱动程序_Default.Page_Load(对象发送方,EventArgs e(+178
System.Web.Util.CaliEventHandlerDelegateProxy.Callback(对象发送方,EventArgs e(+51 System.Web.UI.Control.OnLoad(EventArgs e(+95
System.Web.UI.Control.LoadRecursive((+59
System.Web.UI.Page.ProcessRequestMain(布尔值includeStagesBeforeSyncPoint,Boolean includeStagesAfterSyncPoint(+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对象的注释变量,您在使用它时有任何错误吗?

查找firefox的安装位置例如C:\Program Files\Mozilla Firefox\Firefox.exe

FirefoxOptions option = new FirefoxOptions();
option.BrowserExecutableLocation = "C:\Program Files\Mozilla Firefox\firefox.exe";

//geckodriver.exe文件在项目解决方案中的位置字符串路径=";C://用户//v-sacgupta//source//repos//PracticeExcersie/Practiceexcersie/drivers//";;

driver = new FirefoxDriver(path + @"/drivers/", option);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://google.com");

相关内容

最新更新