无法将 lambda 表达式转换为“字符串”类型;因为它不是委托类型

发布于 2024-10-13 19:07:48 字数 1510 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-10-20 19:07:48

鉴于 这里的代码,对我来说看起来不错。

您是否有可能使用旧版本的 WatiN,它没有该过载?如果您查看 Reflector 中的 WindowsEnumerator,您是否看到此重载?

public IList<Window> GetChildWindows(IntPtr hwnd,
                                     WindowEnumConstraint constraint)

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?

public IList<Window> GetChildWindows(IntPtr hwnd,
                                     WindowEnumConstraint constraint)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文