2016-07-05 48 views
2

我想運行一個簡單的程序,但得到以下錯誤:PATH錯誤Visual Studio中硒的webdriver

An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll

Additional information: Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista

代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Firefox; 

namespace selenium 
{ 
    class Program 
    { 
      static void Main(string[] args) 
     { 
      IWebDriver driver = new FirefoxDriver(); 

      driver.Navigate().GoToUrl("http://www.reuters.com"); 
      driver.Manage().Window.Maximize(); 

      IWebElement searchInput = driver.FindElement(By.XPath("//html/body/div[10]/div[3]/div/td[1]")); 
      searchInput.GetAttribute("value").ToString(); 

      driver.Close();   

     } 
    } 
} 

我檢查了環境變量,我有以下在路徑中:

PATH=C:\Program Files\Mozilla Firefox\firefox.exe

我目前正在運行Windows 10,Visual Studio 2015和selenium Webdriver 2 .53.0

+2

Windows'PATH'是一個目錄列表,而不是文件名。請嘗試將其改爲「PATH = C:\ Program Files \ Mozilla Firefox」。 – dxiv

+0

非常感謝。它像一個魅力工作 – user2434600

+0

[在PATH中找不到firefox二進制文件的可能的重複。確保安裝firefox](http://stackoverflow.com/questions/20950748/cannot-find-firefox-binary-in-path-make-sure-firefox-is-installed) – JeffC

回答

1

在PATH中找不到firefox二進制文件。確保安裝firefox C#的解決方案。

var opt = new FirefoxOptions 
{ 
    BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe" 
}; 
var driver = new FirefoxDriver(opt);