C# Windows安全对话框问题

C# Windows安全对话框问题,c#,watin,C#,Watin,我在使用WatiN处理Win7中的windows安全弹出窗口时遇到问题。我在这里尝试解决方案: [1] :(最后的答案)。按原样使用代码,无需修改,我的呼叫: Ie.DialogWatcher.Add(new Windows7LogonDialogHandler(user, passw)); Ie.GoTo(url); 但是得到错误: Exception was thrown while DialogWatcher called HandleDialog: System.InvalidOper

我在使用WatiN处理Win7中的windows安全弹出窗口时遇到问题。我在这里尝试解决方案: [1] :(最后的答案)。按原样使用代码,无需修改,我的呼叫:

Ie.DialogWatcher.Add(new Windows7LogonDialogHandler(user, passw));
Ie.GoTo(url);
但是得到错误:

Exception was thrown while DialogWatcher called HandleDialog: System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
在这一点上:

var another = (from AutomationElement list in lists
                               where list.Current.ClassName == "UserTile"
                               where list.Current.Name == "Use another account"
                               select list).First();

我错过了什么?

尝试
.FirstOrDefault()
而不是
.First()
-这样,如果没有匹配的项,它将返回
null
,而不是抛出异常。使用.FirstOrDefault()我在另一个.SetFocus()上获得NullReferenceException;这是因为
.FirstOrDefault()
正在返回
null
,因为列表中没有匹配的项。