【发布时间】:2014-07-23 20:52:51
【问题描述】:
我的源代码是从 selenium 文档站点复制的。我没有做任何改变。 http://docs.seleniumhq.org/docs/03_webdriver.jsp#user-input-filling-in-forms 我通过 NuGet 安装了 Selenium 库,包括 Selenium Remote Control(RC)、Selenium WebDriver Mono、Selenium WebDriver 支持类、Selenium WebDriver 和 Selenium WebDriver 支持的 Selenium。
当我运行此代码时,会打开一个新的 Firefox 窗口。但是 Firefox 没有导航到 URL,它只是卡住了,没有加载任何内容。 我尝试了 Firefox v27、v29、v30 和 v31,它们都不起作用。
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
// Requires reference to WebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
}
}
【问题讨论】:
-
请注意,当前的 NuGet 包是 v2.42.0,下一个版本(source)将提供对 Firefox 30 的支持。
-
谢谢,这是一个错误。我测试了不同版本的 Firefox。版本 17、24、25 工作正常。 27~31版本不行。
标签: c# testing selenium-webdriver