我正在使用Fiddler Core,当我按“t”获取信任根证书时,它会显示一个“安全警告”对话框,按是或否
我想自动执行此部分,当对话框打开时,我的控制台应用程序会自动点击是。
答案 0 :(得分:1)
如果你想点击另一个窗口中的按钮 - 首先找到窗口的标题和类名。这可以使用Spy ++完成,它位于开始菜单文件夹(Microsoft Visual Studio 2010 / Visual Studio Tools / Spy ++)中。在间谍++中只需按下搜索/查找窗口...,而不是指向所需的窗口。
现在您可以发送密钥'输入'到你的窗口(或首先发送'标签',如果[no]按钮有效)
这是一个链接How to: Simulate Mouse and Keyboard Events in Code
示例(适用于我的Firefox):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Temp
{
class Program
{
static void Main(string[] args)
{
bool IsDone = false;
while (IsDone == false)
{
// Get a handle to the Firefox application. The window class
// and window name were obtained using the Spy++ tool.
IntPtr firefoxHandle = FindWindow("MozillaWindowClass", null);
// Verify that Firefox is a running process.
if (firefoxHandle == IntPtr.Zero)
{
// log of errors
Console.WriteLine("Firefox is not running.");
// wait 1 sec and retry
System.Threading.Thread.Sleep(1000);
continue;
}
// Make Firefox the foreground application and send it commands
SetForegroundWindow(firefoxHandle);
// send keys to window
System.Windows.Forms.SendKeys.SendWait("google.com");
System.Windows.Forms.SendKeys.SendWait("{tab}");
System.Windows.Forms.SendKeys.SendWait("{enter}");
// yeah ! job's done
IsDone = true;
}
}
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}