无法将 lambda 表达式转换为“字符串”类型;因为它不是委托类型
w => w.ClassName == "按钮" && new WinButton(w.Hwnd).Title == "OK"
我正在使用一个类,该类在在 Watin 上测试网站时打开的所有对话框窗口上单击“确定”。但是这一行给出了 lambda 表达式无法转换为字符串类型的错误,因为它不是委托类型。
我已经使用 System.Linq 但仍然无法工作
请帮助我!
整个代码如下:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;
using SCO.Automated.Testing.Service;
using WatiN.Core.DialogHandlers;
using WatiN.Core.Native.Windows;
using WatiN.Core.Native.InternetExplorer;
namespace SCO.Automated.Testing.Service
{
public class OKDialogHandler : BaseDialogHandler
{
public override bool HandleDialog(Window window)
{
var button = GetOKButton(window);
if (button != null)
{
button.Click();
return true;
}
else
{
return false;
}
}
public override bool CanHandleDialog(Window window)
{
return GetOKButton(window) != null;
}
private WinButton GetOKButton(Window window)
{
var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
if (windowButton == null)
return null;
else
return new WinButton(windowButton.Hwnd);
}
}
}
w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK"
I am using a class that clicks 'OK' on the all dialog windows that opens while testing a website on Watin. But this line gives an error of lambda expression cannot be converted to type string because it is not a delegate type.
I have used using System.Linq and still does not work
Please help me out!
The whole code is as follows:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;
using SCO.Automated.Testing.Service;
using WatiN.Core.DialogHandlers;
using WatiN.Core.Native.Windows;
using WatiN.Core.Native.InternetExplorer;
namespace SCO.Automated.Testing.Service
{
public class OKDialogHandler : BaseDialogHandler
{
public override bool HandleDialog(Window window)
{
var button = GetOKButton(window);
if (button != null)
{
button.Click();
return true;
}
else
{
return false;
}
}
public override bool CanHandleDialog(Window window)
{
return GetOKButton(window) != null;
}
private WinButton GetOKButton(Window window)
{
var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
if (windowButton == null)
return null;
else
return new WinButton(windowButton.Hwnd);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于 这里的代码,对我来说看起来不错。
您是否有可能使用旧版本的 WatiN,它没有该过载?如果您查看 Reflector 中的
WindowsEnumerator
,您是否看到此重载?Given the code here, that looks fine to me.
Is it possible that you're using an older version of WatiN which doesn't have that overload? If you look in
WindowsEnumerator
in Reflector, do you see this overload?