本文介绍了< HTML> < head> < title>硒Firefox Webdriver文本为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7上使用Firefox 21和C#WebDriver 2.33.我困惑为什么以下测试失败(我只是要检查我的配置是否正确设置).这会在其他浏览器中传递.

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"));
}

推荐答案

Selenium WebDriver的text函数将仅返回用户在页面本身上可见的文本.标题文本在页面上在技术上不可见(在浏览器的chrome标题部分中显示).

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).

相反,Selenium WebDriver的方法将返回您可以使用的页面标题:

Instead, Selenium WebDriver has a method that will return the title of a page that you can use:

driver.Title;

因此您的代码变为:

public void TestGoogleStillExists(IWebDriver webDriver)
{
    webDriver.Navigate().GoToUrl("http://www.google.com");
    var title = webDriver.Title;
    Assert.That(title, Is.EqualTo("Google"));
}

这篇关于< HTML> < head> < title>硒Firefox Webdriver文本为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:37