0

我有一個超級簡單的測試腳本(下面)開始使用WebDriver。當我運行測試(C# - Visual Studio 2015)時,它會打開Firefox瀏覽器,然後不執行任何操作。Selenium Webdriver打開Firefox,然後死亡

有幾個職位在那裏,談了以下問題,這我也越來越:

OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000 milliseconds. Attempted to connect to the following addresses: 127.0.0.1:7055.

但對於這個問題這些職位是很老,也有一個主要的difference-他們的FF瀏覽器沒有打開;我的確。

錯誤: enter image description here

代碼:

using Microsoft.VisualStudio.TestTools.UnitTesting; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Firefox; 

namespace seleniumDemo 
{ 
    [TestClass] 
    public class UnitTest1 
    { 
     static IWebDriver driverFF; 

     [AssemblyInitialize] 
     public static void SetUp(TestContext context) 
     { 
      driverFF = new FirefoxDriver(); 
     } 

     [TestMethod] 
     public void TestFirefoxDriver() 
     { 
      driverFF.Navigate().GoToUrl("http://www.google.com"); 
      driverFF.FindElement(By.Id("lst-ib")).SendKeys("Selenium"); 
      driverFF.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter); 
     } 
    } 
} 

這個問題是從什麼被認爲是重複的,因爲FireFox瀏覽器實際上在這種情況下打開不同。在其他問題中,它根本沒有迴應。

+1

最有可能的版本不兼容性。檢查您使用的硒版本是否支持Firefox的版本 –

+0

有看這裏http://stackoverflow.com/questions/38676719/fail-to-launch-mozilla-with-selenium –

+0

可能重複[無法打開瀏覽器與Firefox更新後的Selenium](http://stackoverflow.com/questions/37761668/cant-open-browser-with-selenium-after-firefox-update) – Mobrockers

回答

0

它似乎與Selenium和Firefox版本不兼容。當我的機器上的硒無法與firefox進行通信時,我也遇到了同樣的錯誤。我將firefox升級到了46.x,並開始工作。

您可以在網上找到版本兼容性信息,或者參考selenium changelog。

0

使用MarrioneteDriver可以使用最新版本的Firefox。

下面是Java代碼,你可以在C#編寫accordigly(請確保您已在項目文件夾BrowserDriver文件夾下geckodriver.exe)

System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/BrowserDrivers/geckodriver.exe"); 
     DesiredCapabilities cap = DesiredCapabilities.firefox(); 
     cap.setCapability("marionette", true); 
     WebDriver driver = new MarionetteDriver(cap); 
0

您可以從下面下載最新版本的MarrioneteDriver

https://github.com/mozilla/geckodriver/releases 

你應該木偶可執行文件到Windows系統路徑:

To add the Marionette executable to Windows system path you need update the Path system variable and add the full directory to the executable.

To do this, right-click on the Start menu and select System. On the left-side panel click Advanced system settings and then Environment Variables button from System Properties window. Now the only step left to do is to edit Path system variable and add the full directory to your geckodriver (you may need to add a semi-colon before doing this, if not already present) and you’re good to go.

然後簡單地創建您的驅動程序實例:

var driver = new FirefoxDriver(new FirefoxOptions()); 
相關問題