2015-12-02 22 views
0

我使用的是Firefox,並且圖標在關閉之前會在任務欄中顯示半秒。然後,Firefox將與URL再次啓動Selenium:當創建新的IWebDriver時,瀏覽器啓動然後關閉,然後重新啓動一個新的會話

約:空白&的utm_content = firstrun

(即使主頁被設置爲谷歌)。

這可能是一個環境變量的問題?我沒有碰過這條路。

基本上,這是阻止我,因爲其他的語句會碰上NoSuchElementException異常......

這是我的代碼:

 using System; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Firefox; 
using OpenQA.Selenium.Support.UI; 

     namespace HomeAuto { 
      class Program 
      { 
       static void Main(string[] args) 
       { 
        IWebDriver driver = new FirefoxDriver(); 
        Thread.Sleep(5000); 
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); 
        driver.Navigate().GoToUrl("www.trademe.co.nz"); 
        SelectElement categories = new SelectElement(driver.FindElement(By.Id("SearchType"))); 
        categories.SelectByValue("202"); 
        IWebElement searchBox = driver.FindElement(By.Id("searchString")); 
        searchBox.SendKeys("Some game"); 
        searchBox.Submit(); 

        driver.Close(); 

       } 
      } 
     } 
+0

WaitForElement :) –

+0

不幸的是,即使我評論構造下的所有內容出現問題。我已經嘗試了WaitForElement而不是睡眠者,但無濟於事。 – Lionfish

回答

2

發現問題是在URL中 - 即使瀏覽器可以在不瀏覽協議URI。如果導航方法變更爲

一切正常:

driver.Navigate().GoToUrl("https://www.trademe.co.nz"); 
+0

你能否詳細說明這一點@Lionfish。運行我的腳本時遇到類似的問題,一旦Firefox打開它,就會有以下URL:about:blank&utm_content = firstrun。我使用PhantomJS運行完全相同的腳本,它效果很好,但Firefox給出了這個錯誤。 – ntk4

相關問題