当我在 NUnit 中运行这个程序时,出现错误
你调用的对象是空的。
虽然这不是原始程序,但我也遇到了类似的错误。任何帮助表示赞赏。异常发生于
driver.Navigate().GoToUrl("http://www.yahoo.com/");
程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
namespace Class_and_object
{
[TestFixture]
public class Class1
{
IWebDriver driver = null;
[Test]
public void test1()
{
class2 obj = new class2();
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
obj.method();
}
}
public class class2
{
IWebDriver driver = null;
public void method()
{
driver.Navigate().GoToUrl("http://www.yahoo.com/");
}
}
}
看看你的代码:
public class class2
{
IWebDriver driver = null;
public void method()
{
driver.Navigate().GoToUrl("http://www.yahoo.com/");
}
}
当然你会得到一个NullReferenceException
- driver
总是null
.
目前尚不清楚您期望在这里发生什么 - 但也许您打算通过FirefoxDriver
你实例化于test1
into method
通过参数?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)