110,561
社区成员
发帖
与我相关
我的任务
分享
using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Runtime.InteropServices;
9
10 namespace BrowserMouseClick
11 {
12 public partial class Form1 : Form
13 {
14 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
15 static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
16
17 [DllImport("user32.dll", SetLastError = true)]
18 static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
19
20 [DllImport("user32.dll", CharSet = CharSet.Auto)]
21 static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
22
23 public Form1()
24 {
25 InitializeComponent();
26 }
27
28 private void Form1_Load(object sender, EventArgs e)
29 {
30 webBrowser1.Navigate("http://www.devpub.com");
31 }
32
33 private void btnMouseClick_Click(object sender, EventArgs e)
34 {
35 int x = 100; // X coordinate of the click
36 int y = 80; // Y coordinate of the click
37 IntPtr handle = webBrowser1.Handle;
38 StringBuilder className = new StringBuilder(100);
39 while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
40 {
41 handle = GetWindow(handle, 5); // Get a handle to the child window
42 GetClassName(handle, className, className.Capacity);
43 }
44
45 IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
46 IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
47 const uint downCode = 0x201; // Left click down code
48 const uint upCode = 0x202; // Left click up code
49 SendMessage(handle, downCode, wParam, lParam); // Mouse button down
50 SendMessage(handle, upCode, wParam, lParam); // Mouse button up
51 }
52 }
53 }
showDown: function (elementInput, message, xPos, pointerXPos, yPos, pointerYPos, height, timeout) {
// <span class="fHintDown"><span>This is the message.<span><span class="hint-pointer"> </span></span>
var hint = document.getElementById('fHintDown');
var hintPointer = null;
if (hint == null) {
var hint = document.createElement("SPAN");
hint.className = 'hint';
var hintMsg = document.createElement("SPAN");
hint.appendChild(hintMsg);
hintPointer = document.createElement("SPAN");
hintPointer.className = 'hint-pointer-down';
hint.appendChild(hintPointer);
hint.id = 'fHintDown';
hint.style.top = '10px';
hint.style.left = '10px';
hint.style.zIndex = 999999;
hint.onclick = function () { // Hide onclick
hint.style.display = 'none';
};
document.body.appendChild(hint);
};
hintPointer = hint.lastChild;
hint.firstChild.innerHTML = message;
if (this.timeOutHideTooltip) {
clearTimeout(this.timeOutHideTooltip);
this.timeOutHideTooltip = null;
};
if (typeof (timeout) == 'undefined') {
timeout = 1000;
}
this.timeOutHideTooltip = setTimeout(function () {
if (hint == null) {
return;
}
hint.style.display = 'none';
}, timeout); // Auto hide in 1s
if (elementInput != null) {
if (typeof xPos == 'undefined') {
xPos = 0;
}
if (typeof pointerXPos == 'undefined') {
pointerXPos = 10;
}
if (typeof yPos == 'undefined') {
yPos = -45;
}
if (typeof (pointerYPos) == 'undefined') {
pointerYPos = 38;
}
if (typeof (height) == 'undefined') {
height = 18;
}
hint.style.height = height + 'px';
hintPointer.style.left = (pointerXPos + 'px');
hintPointer.style.top = (pointerYPos + 'px');
var pos = Validators.utils.findPosRelativeToViewport(elementInput);
hint.style.left = (pos[0] + xPos) + 'px';
hint.style.top = (pos[1] + yPos) + 'px';
elementInput.onchange = function () {
hint.style.display = 'none';
};
elementInput.focus();
};
hint.style.display = 'block';
}
IHTMLElement i=(IHTMLElement)all.item("password", 0);
i.click();
if (((DispHTMLInputElement)all.item("password", 0)).value == null)
((DispHTMLInputElement)all.item("password", 0)).value = =“password123”;
这样没有效果,不一定是在ONKEYUP里记录的,好像没有跟踪到,可能是在样式或者BING里生成的JS,确还是根据鼠标动作形成的。大家给点思路 private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Url = new Uri("http://www.baidu.com");
}
private void button1_Click(object sender, EventArgs e)
{
if (this.webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
HtmlElement text = this.webBrowser1.Document.All["kw"];
HtmlElement button = this.webBrowser1.Document.All["su"];
text.SetAttribute("value", "guwei4037");
button.InvokeMember("click");
}
}