2011-12-12 95 views
1

我得到一个空白页,当尝试在硒GRID2使用C#代码段打开所需页面(google.com)在Firefox浏览器。 FF页面在我手动关闭之前不会关闭。相同的代码适用于IE和Chrome浏览器。空白页/ NUnit的

任何帮助,非常感谢。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Remote; 
using NUnit.Framework; 

namespace WebDriverExample 
{ 
public class Class1 
{ 
    [TestFixture] 
    public class Testing 
    { 
     private IWebDriver driver; 

     [SetUp] 
     public void SetUp() 
     { 
      driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.Firefox()); 
     } 

     [Test] 
     public void TestGoogle() 
     { 
      driver.Navigate().GoToUrl("http://www.google.com"); 
     } 

     [TearDown] 
     public void TearDown() 
     { 
      driver.Quit(); 
     } 
    } 
} 
} 

回答

1

我不熟悉C#语法,但我用的webdriver不加载在多个场合的页面恶魔,并看到了几个不同的原因搏斗。没有什么明显的错误与您的代码(虽然driver.Navigate().GoToUrl(myurl)作用似乎是不必要的冗长;在蟒蛇,它是driver.get(myurl))。

假设这不是问题,这是最有可能是版本的问题。当webdriver启动Firefox时,它会给它一个自定义的扩展二进制文件,它随着webdriver版本而改变。 Firefox 8(现在非常流行)需要一个相当新的webdriver扩展版本,可能最新版本为2.12。

除此之外,请原谅我“插入问题”的问题,但我也犯了错误:确保在测试顶部附近有一个webdriverobject.get(url),然后再尝试找到任何页面元素。