title: Visual Studio 2010 (win 7 x64) Selenium Unit Test Keeps Pending
body: <p>I am trying for several hours to make a Unit Testing with Selenium driver for a custom website. The problem is, my first test case is always pending. I haven't written any other. I tried several different tutorials, but none works. What I have done:</p>
  
  <ul>
  <li>Install Selenium WebDriver through NuGet Console (have a reference);</li>
  <li>Install Selenium WebDriver.Support through NuGet (have a reference);</li>
  <li>I have even turned the firewall off;</li>
  </ul>
  
  <p>Lastly, I am following the tutorial on this page <a href="http://www.dotnet-developer.de/2012/11/vbnet/tips-and-tricks-for-selenium-webtests/" rel="nofollow">dotnet-developer.de</a>!  The tutorial does not work too. It is given in vb.net, but I have translated it in C# as follows:</p>
  
  <pre><code>using System;
  using System.Text;
  using System.Collections.Generic;
  using System.Linq;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Firefox;
  using OpenQA.Selenium.Support.UI;
  
  namespace FastMenuSeleniumTests
  {
      /// &lt;summary&gt;
      /// Summary description for UnitTest1
      /// &lt;/summary&gt;
      [TestClass]
      public class UnitTest1
      {
  
          public IWebDriver driver;
          const string BaseURL = "http://www.bing.com";
  
          public UnitTest1()
          {
              // do nothing
          }
  
          private TestContext testContextInstance;
  
          /// &lt;summary&gt;
          ///Gets or sets the test context which provides
          ///information about and functionality for the current test run.
          ///&lt;/summary&gt;
          public TestContext TestContext
          {
              get
              {
                  return testContextInstance;
              }
              set
              {
                  testContextInstance = value;
              }
          }
  
          #region Additional test attributes
          //
          // You can use the following additional attributes as you write your tests:
          //
          // Use ClassInitialize to run code before running the first test in the class
          // [ClassInitialize()]
          // public static void MyClassInitialize(TestContext testContext) { }
          //
          // Use ClassCleanup to run code after all tests in a class have run
          // [ClassCleanup()]
          // public static void MyClassCleanup() { }
          //
          // Use TestInitialize to run code before running each test 
          [TestInitialize()]
          public void TestInitialization() 
          {
              driver = new FirefoxDriver();
              //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
              //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
          }
          //
          // Use TestCleanup to run code after each test has run
          [TestCleanup()]
          public void TestCleanup() 
          {
              driver.Quit();
          }
          //
          #endregion
  
          [TestMethod]
          public void TestMethod1()
          {
              IWebElement SearchBox = default(IWebElement);
              IWebElement FirstResult = default(IWebElement);
  
              //Go to Bing Homepage
              driver.Navigate().GoToUrl(BaseURL);
  
              //Get Handle for Searchbox
              SearchBox = GetWebElement(driver, By.Id("sb_form_q"), 10);
  
              //Enter Search Text
              SearchBox.SendKeys("dotnet-developer.de");
  
              //Different ways to start the search
              //Method 1: Press ENTER
              SearchBox.SendKeys(Keys.Enter);
  
              //Method 2: Grab Search-Button and click it
              //Dim SearchButton As IWebElement
              //SearchButton = GetWebElement(driver, By.Id("sb_form_go"), 10)
              //SearchButton.Click()
  
              //Now get the first result returned by Bing search
              FirstResult = GetWebElement(driver, By.XPath("//ul[@class='sb_results']/li/div/div/div/h3/a"), 10);
  
              //Method 1: Compare the subject
              string ExpectedText = "dotnet-developer.de | Tips for vb.net,…";
              Assert.AreEqual(ExpectedText, FirstResult.Text, "Subject is not correct");
  
              //Method 2: Compare the link
              string ExpectedURL = "http://www.dotnet-developer.de/";
              Assert.AreEqual(ExpectedURL, FirstResult.GetAttribute("href"), "URL is not correct!");
          }
  
          /// &lt;summary&gt;
          /// Retrieve Web Element using default driver and default timeout
          /// &lt;/summary&gt;
          /// &lt;param name="definition"&gt;Definition of the WebElement to grab&lt;/param&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          /// &lt;remarks&gt;&lt;/remarks&gt;
          private IWebElement GetWebElement(OpenQA.Selenium.By definition)
          {
              const int DefaultTimeout = 10;
              return GetWebElement(definition, DefaultTimeout);
          }
  
          /// &lt;summary&gt;
          /// Retrieve Web Element using default driver
          /// &lt;/summary&gt;
          /// &lt;param name="definition"&gt;Definition of the WebElement to grab&lt;/param&gt;
          /// &lt;param name="timeoutSeconds"&gt;Seconds to wait until a timeout is thrown&lt;/param&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          /// &lt;remarks&gt;&lt;/remarks&gt;
          private IWebElement GetWebElement(OpenQA.Selenium.By definition, int timeoutSeconds)
          {
              return GetWebElement(driver, definition, timeoutSeconds);
          }
  
          /// &lt;summary&gt;
          /// Waits until the given element is enabled and visible
          /// &lt;/summary&gt;
          /// &lt;param name="webDriver"&gt;&lt;/param&gt;
          /// &lt;param name="definition"&gt;&lt;/param&gt;
          /// &lt;param name="seconds"&gt;&lt;/param&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          /// &lt;remarks&gt;Needs to wait for .displayed because for e.g. in a collapsed Treeview all nodes are available but not visible 
          /// if the parent node is collapsed and therefore the following error would appear:
          /// OpenQA.Selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
          /// &lt;/remarks&gt;
          private IWebElement GetWebElement(IWebDriver webDriver, OpenQA.Selenium.By definition, int seconds)
          {
              WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(seconds));
  
              wait.Until(d =&gt; { return d.FindElement(definition).Enabled &amp; d.FindElement(definition).Displayed; });
  
              return webDriver.FindElement(definition);
          }
  
      }
  }
  </code></pre>