简体   繁体   English

如何设置Selenium 3.0,在C#中出现错误“ geckodriver.exe文件不存在……”

[英]How to set up selenium 3.0, getting error “The geckodriver.exe file does not exist…” in c#

Updated selenium in visual studio to 3.0 and firefox to 47.0 and now I'm getting this error when I try to use local webdriver mode: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. 在Visual Studio中将selenium更新为3.0,将Firefox更新为47.0,现在当我尝试使用本地webdriver模式时出现此错误:geckodriver.exe文件在当前目录中或PATH环境变量的目录中不存在。

When I'm using remote mode (seleniumhub), it works fine even if it uses firefox 45.0 version. 当我使用远程模式(seleniumhub)时,即使它使用的是firefox 45.0版本,也可以正常工作。

Tried to search for some examples, but did not found anything for c#, only for java and still could not make it work. 试图搜索一些示例,但没有为c#找到任何东西,仅为java找到了东西,但仍然无法使它工作。

my webdriver setup: 我的网络驱动程序设置:

 switch (ConfigurationManager.AppSettings["WebDriverMode"].ToLower())
                {
                    case "local":
                        switch (ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower())
                        {
                            case "firefox":
                                driver = new AdvancedFirefoxDriver();
                                break;
                            case "ie":
                                driver = new AdvancedInternetExplorerDriver();
                                break;
                            case "chrome":
                                driver = new AdvancedChromeDriver();
                                break;
                            default:
                                throw new NotImplementedException(string.Format("WebDriverBrowserCapabilities of \"{0}\" is not implemented for {1} mode", ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower(), ConfigurationManager.AppSettings["WebDriverMode"].ToLower()));
                        }

                        break;
                    case "remote":
                        var huburl = new Uri(ConfigurationManager.AppSettings["SeleniumHubAddress"]);
                        DesiredCapabilities capabilities;
                        switch (ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower())
                        {
                            case "firefox":
                                capabilities = DesiredCapabilities.Firefox();
                                break;
                            case "ie":
                                capabilities = DesiredCapabilities.InternetExplorer();
                                break;
                            case "chrome":
                                capabilities = DesiredCapabilities.Chrome();
                                break;
                            default:
                                throw new NotImplementedException(string.Format("WebDriverBrowserCapabilities of \"{0}\" is not implemented for {1} mode", ConfigurationManager.AppSettings["WebDriverBrowserCapabilities"].ToLower(), ConfigurationManager.AppSettings["WebDriverMode"].ToLower()));
                        }

                        capabilities.IsJavaScriptEnabled = true;
                        driver = new AdvancedRemoteWebDriver(huburl, capabilities);
                        break;
                    default:
                        throw new NotImplementedException();
                }

From selenium 3.0, you have to use the geckodriver for Firefox browser. 从硒3.0开始,您必须使用Firefox浏览器的geckodriver

download the latest geckodriver from here https://github.com/mozilla/geckodriver/releases 从这里https://github.com/mozilla/geckodriver/releases下载最新的geckodriver

You have two options: 您有两种选择:

  1. enter geckodriver path in Windows System Environment Variable PATH . 在Windows系统环境变量PATH输入geckodriver路径。
  2. Or specify the location of the geckodriver.exe programmatically as follows. 或以编程方式指定geckodriver.exe的位置,如下所示。

System.Environment.SetEnvironmentVariable("webdriver.gecko.driver",@"/path/to/geckodriver.exe"

Note: System restart may be required if you set PATH environment variable. 注意:如果您设置PATH环境变量,则可能需要重新启动系统。

From Firefox 47 onwards (Excluding it), Selenium uses geckodriver capabilities by default. 从Firefox 47开始(不包括Firefox),Selenium默认使用geckodriver功能。 For 47 and previous versions onwards, you may need to turn off this capability so that Selenium can use Firefox built-in support like we used to work with these versions. 对于47及更早的版本,您可能需要关闭此功能,以便Selenium可以像以前使用这些版本一样使用Firefox内置支持。

JAVA version to achieve the same: JAVA版本实现相同:

DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false);  // to disable marionette.
WebDriver driver = new FirefoxDriver(d);

References: 参考文献:

  1. how to set system properties in C# 如何在C#中设置系统属性
  2. https://msdn.microsoft.com/en-us/library/z46c489x.aspx https://msdn.microsoft.com/zh-CN/library/z46c489x.aspx
  3. https://superuser.com/questions/317631/setting-path-in-windows-7-command-prompt https://superuser.com/questions/317631/setting-path-in-windows-7-command-prompt
  4. https://stackoverflow.com/a/40466109/2575259 https://stackoverflow.com/a/40466109/2575259

I a similar issue with the Chrome driver for Selenium, I was following along a course on building an automation framework and I installed the NuGet package under framework references, instead of installing it under tests. 与Selenium的Chrome驱动程序类似的问题,我遵循了有关构建自动化框架的课程,并且我在框架引用下安装了NuGet软件包,而不是在测试下安装了它。 在此处输入图片说明

您可以从此处下载geckodriver: https : //github.com/mozilla/geckodriver/releases ,然后只需将文件目录添加到FirefoxDriver构造函数中,如下所示:
new FirefoxDriver("geckoDriverDirectory")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决错误文件 geckodriver.exe 正被另一个使用 Firefox 和 Selenium C# 的进程使用 - How to address the error The file geckodriver.exe is being used by another process using Firefox and Selenium C# ceckodriver.exe硒3.8未运行nunit 3.9 - c# - geckodriver.exe selenium 3.8 not running nunit 3.9 geckodriver.exe不在当前目录或路径变量中,Selenium 2.53.1 + Firefox 48 + Selenium 3 Beta - geckodriver.exe not in current directory or path variable, Selenium 2.53.1 + Firefox 48 + Selenium 3 Beta C#Geckodriver / Selenium 3.0-Mozilla 47.0.1会自行停止 - C# Geckodriver / Selenium 3.0 - Mozilla 47.0.1 stops itself IEDriverServer.exe在C#Selenium Web驱动程序中不存在 - IEDriverServer.exe does not exist in C# Selenium Web driver 在 selenium geckodriver 上设置代理 - Set up proxy on selenium geckodriver 发布 ASP.NET Core MVC 2.1 项目时将文件 (geckodriver.exe) 复制到发布文件夹 - Copy file (geckodriver.exe) to publish folder when publishing ASP.NET Core MVC 2.1 project C#Geckodriver硒ff - c# geckodriver selenium ff 隐藏 geckodriver 命令窗口 selenium c# - Hide geckodriver command window selenium c# 我们可以在C#中为宏开发一个.exe文件以在新机器中设置excel文件吗,该机器之前不包含任何宏 - Can we develop a .exe file, in c# for macros to set up excel file in new machine which does not contains any macros earlier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM