2014-07-23 97 views
1

我的源代碼是從selenium docs站點複製的。我沒有做任何改變。我通過NuGet安裝了Selenium庫,包括 Selenium Remote Control(RC),Selenium WebDriver Mono,Selenium WebDriver支持類,Selenium WebDriver和Selenium WebDriver支持的Selenium。Selenium-WebDriver打開了新的Firefox窗口,但未導航到URL

當我運行這段代碼時,打開了一個新的Firefox窗口。但Firefox並沒有導航到URL,它只是卡住了,沒有加載任何東西。 我試過火狐v27,v29,v30和v31,他們都沒有工作。

enter image description here

using OpenQA.Selenium; 
using OpenQA.Selenium.Firefox; 

// Requires reference to WebDriver.Support.dll 
using OpenQA.Selenium.Support.UI; 

class GoogleSuggest 
{ 
static void Main(string[] args) 
{ 
    // Create a new instance of the Firefox driver. 

    // Notice that the remainder of the code relies on the interface, 
    // not the implementation. 

    // Further note that other drivers (InternetExplorerDriver, 
    // ChromeDriver, etc.) will require further configuration 
    // before this example will work. See the wiki pages for the 
    // individual drivers at http://code.google.com/p/selenium/wiki 
    // for further information. 
    IWebDriver driver = new FirefoxDriver(); 

    //Notice navigation is slightly different than the Java version 
    //This is because 'get' is a keyword in C# 
    driver.Navigate().GoToUrl("http://www.google.com/"); 

    // Find the text input element by its name 
    IWebElement query = driver.FindElement(By.Name("q")); 

    // Enter something to search for 
    query.SendKeys("Cheese"); 

    // Now submit the form. WebDriver will find the form for us from the element 
    query.Submit(); 

    // Google's search is rendered dynamically with JavaScript. 
    // Wait for the page to load, timeout after 10 seconds 
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
    wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); 

    // Should see: "Cheese - Google Search" 
    System.Console.WriteLine("Page title is: " + driver.Title); 

    //Close the browser 
    driver.Quit(); 
} 
} 
+0

可能是一個錯誤:https://code.google.com/p/selenium/issues/detail?id=7532 – Stijn

+0

注意,目前的NuGet包是v2.42.0,對Firefox支持30將在下一個版本中提供([source](https://code.google.com/p/selenium/issues/detail?id=7488#c1))。 – Stijn

+0

謝謝,這是一個錯誤。我測試了不同版本的Firefox。版本17,24,25正常工作。版本27〜31不起作用。 – user3026964

回答

0

我有同樣的問題。解決方案是簡單地卸載您當前的Firefox瀏覽器並下載舊版本「我試過2010版本3.6.10很棒」。你的代碼很好,問題在於Mozilla的人們決定不讓任何第三方應用程序來控制Firefox。

好運