我正在尝试在我的SSIS脚本任务中让Watin工作,以便通过在新线程中打开IE、执行一些操作、查找最终值并基本上在父线程中返回/设置该值来进行自动化。
目前我有这个:
public partial class TestWatin{
public void Main()
{
String finalValueFromWeb = "";
Thread runnerThread = new Thread(delegate() { getDAFValue(ref finalValueFromWeb ); });
runnerThread.ApartmentState = ApartmentState.STA;
runnerThread.Start();
runnerThread.Join();
MessageBox.Show(finalValueFromWeb);
//here i want to use the value of finalValueFromWeb to download a file
//but if i try to access finalValueFromWeb the process would fail.
}
//do the Watin stuff here
public void findHiddenURL(String refObject)
{
//setup page controls, press search, grab the value of "hiddenURL"
IE ie = new IE("some_webadress_to_go_to");
ie.Visible = false;
ie.SelectList("testID1").Option("Car").Select();
ie.SelectList("testID2").Option("JAP").Select();
ie.SelectList("testID3").Option("2012").Select();
ie.Button("testSearch").Click();
Link link = ie.Link("hiddenURL");
ie.Close();
//fails here?
refObject = link.Url;
}
}
我希望的基本内容是
findHiddenURL()
查找一个包含CSV url的字符串值。然后我想使用该字符串来下载CSV并处理它。问题出在当我尝试在
findHiddenURL()
内设置finalValueFromWeb
的值时,此过程失败。异常消息显示为The Object Reference is not set to an instance of an object
。请问有谁能告诉我如何解决这个问题?做这种事情的正确方式是什么?谢谢。