Reputation: 6482
I'm using Firefox 21 and C# WebDriver 2.33 on Windows 7. I'm baffled why the following test fails (which I have just to check my configuration is set up correctly). This passes in other browsers.
[Test]
public void FirefoxDriverWorks()
{
var firefoxDriver = new FirefoxDriver();
TestGoogleStillExists(firefoxDriver);
firefoxDriver.Quit();
}
public void TestGoogleStillExists(IWebDriver webDriver)
{
webDriver.Navigate().GoToUrl("http://www.google.com");
var title = webDriver.FindElement(By.CssSelector("head title"));
Assert.That(title.Text, Is.EqualTo("Google"));
}
Upvotes: 2
Views: 3456
Reputation: 1540
Selenium WebDriver's text
function will only return text that is visible to the user on the page itself. The title text is not technically visible on the page (it is displayed in the title section of the chrome in the browser).
Instead, Selenium WebDriver has a method that will return the title of a page that you can use:
driver.Title;
So your code becomes:
public void TestGoogleStillExists(IWebDriver webDriver)
{
webDriver.Navigate().GoToUrl("http://www.google.com");
var title = webDriver.Title;
Assert.That(title, Is.EqualTo("Google"));
}
Upvotes: 6