1

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

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

我只是不断收到这些无效的参数异常。

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

4

1 回答 1

0

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

例如,在 .NET 中使用 SendKeys 右键单击

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());
        }    
    }
}
于 2012-08-13T18:10:57.627 回答