Hi. I'm new to NUnit. I'm running version 2.5.10.11092 on Win 7, 32-
bit. When I try to run a test I get...
SeleniumTests.GoogleTestExportedInCSharpWebDriver.TheGoogleTestExportedInCSharpWebDriverTest:
OpenQA.Selenium.NoSuchElementException : Unable to locate element:
{"method":"css selector","selector":"#gb_2 > span.gbts"}
at
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand
driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String
mechanism, String value)
at
OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String
cssSelector)
at
OpenQA.Selenium.By.<>c__DisplayClass1e.<CssSelector>b__1c(ISearchContext
context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at
SeleniumTests.GoogleTestExportedInCSharpWebDriver.TheGoogleTestExportedInCSharpWebDriverTest()
Here's what I did:
- used Selenium IDE 1.1.0 to create a test, which runs and passes in
Se IDE
- exported the test as C# (WebDriver)
- copied/pasted the C# code into a Visual C# 2010 Express project
- added references to the required dll's
- ensured that there were no errors reported in the code
- built a dll assembly
- put the dll into a folder with the referenced dll's (verified that
the nunit.framework.dll was in this folder)
- created a new NUnit project and added the dll assembly from C#
Express
- clicked Run
The Firefox browser launches, but then the test fails with the message
above. Here is the code that was exported by Se IDE...
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace SeleniumTests
{
[TestFixture]
public class GoogleTestExportedInCSharpWebDriver
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "
http://www.google.com/";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheGoogleTestExportedInCSharpWebDriverTest()
{
driver.Navigate().GoToUrl("/");
driver.FindElement(By.CssSelector("#gb_2 >
span.gbts")).Click();
driver.FindElement(By.CssSelector("#gb_12 >
span.gbts")).Click();
driver.FindElement(By.CssSelector("#gb_8 >
span.gbts")).Click();
driver.FindElement(By.Id("d_launch")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
}
}