使用Watin自动化ContextMenu

时间:2012-08-09 16:09:47

标签: watin

我正在尝试自动化右键单击元素时出现的HTML Contextmenu。我正在使用watin& IE 9。 我已经尝试了以下内容:

    NameValueCollection props = new NameValueCollection();
    props.Add("button", "2");
    tc.FireEvent("click", props);
    tc.FireEvent("mousedown", props);
    tc.FireEvent("mouseup", props);

我只是继续为这些获得一个无效的参数异常。

获取上下文菜单或解决此异常的任何其他建议?

1 个答案:

答案 0 :(得分:0)

您是否尝试过通过Interop发送右键?

例如Right click with SendKeys in .NET

using System;
using System.Runtime.InteropServices;

namespace WinApi
{  
    public class Mouse
    { 
        [DllImport("user32.dll")]
        private static extern void mouse_event(UInt32 dwFlags,UInt32 dx,UInt32 dy,UInt32 dwData,IntPtr dwExtraInfo);

        private const UInt32 MouseEventRightDown = 0x0008;
        private const UInt32 MouseEventRightUp = 0x0010;

        public static void SendRightClick(UInt32 posX, UInt32 posY)
        {
            mouse_event(MouseEventRightDown, posX, posY, 0, new System.IntPtr());
            mouse_event(MouseEventRightUp, posX, posY, 0, new System.IntPtr());
        }    
    }
}