![](/img/trans.png)
[英]How to address the error The file geckodriver.exe is being used by another process using Firefox and Selenium C#
[英]How to set up selenium 3.0, getting error “The geckodriver.exe file does not exist…” in c#
在Visual Studio中將selenium更新為3.0,將Firefox更新為47.0,現在當我嘗試使用本地webdriver模式時出現此錯誤:geckodriver.exe文件在當前目錄中或PATH環境變量的目錄中不存在。
當我使用遠程模式(seleniumhub)時,即使它使用的是firefox 45.0版本,也可以正常工作。
試圖搜索一些示例,但沒有為c#找到任何東西,僅為java找到了東西,但仍然無法使它工作。
我的網絡驅動程序設置:
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();
}
從硒3.0開始,您必須使用Firefox瀏覽器的geckodriver
。
從這里https://github.com/mozilla/geckodriver/releases下載最新的geckodriver
您有兩種選擇:
PATH
輸入geckodriver路徑。 System.Environment.SetEnvironmentVariable("webdriver.gecko.driver",@"/path/to/geckodriver.exe"
注意:如果您設置PATH環境變量,則可能需要重新啟動系統。
從Firefox 47開始(不包括Firefox),Selenium默認使用geckodriver功能。 對於47及更早的版本,您可能需要關閉此功能,以便Selenium可以像以前使用這些版本一樣使用Firefox內置支持。
JAVA版本實現相同:
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false); // to disable marionette.
WebDriver driver = new FirefoxDriver(d);
參考文獻:
您可以從此處下載geckodriver: https : //github.com/mozilla/geckodriver/releases ,然后只需將文件目錄添加到FirefoxDriver構造函數中,如下所示:
new FirefoxDriver("geckoDriverDirectory")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.