c# - 在 Windows 主机中运行 selenium 时出现错误预期的浏览器二进制位置
问题描述
此示例工作:获取 google 的文本并在主页示例 asp.net 中显示测试以在 Windows 主机中正确工作 selenium。
我想在托管 plesk 的 Windows 中运行 selenium。
对我来说错误:
“/”应用程序中的服务器错误。
预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有提供“moz:firefoxOptions.binary”功能,并且在命令行上没有设置二进制标志 (SessionNotCreated)
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.InvalidOperationException:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,未提供“moz:firefoxOptions.binary”功能,命令行上未设置二进制标志 (SessionNotCreated)
源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。堆栈跟踪:
[InvalidOperationException:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,未提供“moz:firefoxOptions.binary”功能,并且命令行上未设置二进制标志(SessionNotCreated)]
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError (响应错误响应)+1059
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 参数)+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(布尔 includeStagesBeforeAsyncPoint,布尔 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
对象的注释变量,您使用它是否有任何错误?
推荐阅读
- vue.js - Vue js表格动作按钮不显示
- angular - 如何在这样的自定义场景中以角度调用http post?
- mysql - 无法将 OKE Kubernetes 集群连接到集群外部的 Oracle MySQL 数据库实例
- html - bootstrap 4.6 按钮是否应该在活动时具有嵌入阴影?
- python - 输入数据有问题?Tensorflow:UnimplementedError:不支持将字符串转换为浮点数
- amazon-web-services - Can AWS email errors logged to CloudWatch by multiple Lambda functions?
- javascript - 电报机器人付款 - 成功付款后显示收据
- azure - 如何发送包含 & 符号的 Azure 应用程序配置值?
- swift - CompositionalLayout 项目定制
- javascript - TypeError:无法设置属性“值”为空 | 在文本字段中插入文本