2012-08-09 36 views
1

我試圖自動化右鍵單擊元素時出現的HTML上下文菜單。我使用的是華廷& IE 9 我已經試過如下:使用Watin自動執行ContextMenu

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

我只是不斷得到這些無效的參數異常。

任何其他建議獲取上下文菜單或解決此異常?

回答

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()); 
     }  
    } 
} 
+0

SendRightClick工作正常,但如何讓元素x和y相對於座標使用華廷篩選? – rahoolm 2014-08-28 10:02:38