繁体   English   中英

Selenium-WebDriver打开了新的Firefox窗口,但没有导航到URL

[英]Selenium-WebDriver opened the new Firefox window, but didn’t navigate to URL

我的源代码是从硒文档站点复制的。 我没有做任何改变。 http://docs.seleniumhq.org/docs/03_webdriver.jsp#user-input-filling-in-forms我通过NuGet安装了Selenium库,包括Selenium远程控制(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();
}
}

我曾经也有过一样的问题。 解决方案是简单地卸载您当前的firefox浏览器并下载旧版本“我尝试2010年版本3.6.10很好用”。 您的代码很好,问题出在Mozilla人们决定不授予任何第三方应用程序控制Firefox的权利。

祝好运

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM