如果有id,根据id找 var o:OleVariant; i:integer; Doc:IHTMLDocument2; userinputelement,pwdinputelement,ValidateElement:ihtmlinputelement; begin Doc:=WebBrowser1.document as ihtmldocument2; if doc=nil then exit; userinputelement:=(doc.all.item('payFeeOnlineInfo.productNO',0) as ihtmlinputelement); userinputelement.value:=ed_ltcode.Text; userinputelement:=(doc.all.item('payFeeOnlineInfo.productNOAgain',0) as ihtmlinputelement); userinputelement.value:=ed_ltcode.Text; userinputelement:=(doc.all.item('payFeeOnlineInfo.checkCode',0) as ihtmlinputelement); userinputelement.value:=ed_ltyz.Text; userinputelement:=(doc.all.item('payFeeOnlineInfo.payFee',0) as ihtmlinputelement); userinputelement.value:=ed_ltprice.Text; o:=doc.all.item('submit0',0); state := 101; o.click; //o:=doc.all.item('payButton',0); //o.click;end;
Private Sub ShellExecuteIE(Mode As Integer) On Error Resume Next Dim Titles As String Dim IEList As New SHDocVw.ShellWindows Dim Doc Dim i As Integer Dim j As Integer Dim LocalNames As String Dim Name As String, Password As String, Security As String 'If FormType = 1 Then 'Name = "username" 'Password = "password" 'Security = "ekey" ' Else Name = "idInput" Password = "pwdInput" 'Security = "username5" 'End If 'If FormType = 1 Then 'Titles = "纵横天下官方网站 - 盛大网络" 'Else Titles = "126网易免费邮--你的专业电子邮局" 'End If '遍历当前浏览器窗口 j = IEList.Count For i = 0 To j - 1 '找到需要的IE窗口 LocalNames = Left(IEList.Item(i).LocationName, Len(Trim(Titles))) If LocalNames = Trim(Titles) Then '获得浏览器文档对象,填写表单 Set Doc = IEList.Item(i).Document Doc.body.All("" & Name & "").Value = Trim(Text1.Text) '用户名 Doc.body.All("" & Password & "").Value = Trim(Text2.Text) '密码 'Doc.body.All("" & Security & "").Value = Trim(Text3.Text) '密保 If Mode = 1 Then
Else '直接提交网页 'If FormType = 1 Then 'Doc.Forms("login").Submit 'Else Doc.Forms("loginBtn").Submit 'End If End If Command3.Enabled = True Command4.Enabled = True Exit Sub End If Next MsgBox "登录入口未加载完毕,请稍候再试!", vbSystemModal + vbOKOnly + vbExclamation, "Error" Command3.Enabled = True Command4.Enabled = True End Sub找了个vb的,用126测试,可以赋值,但是提交不执行!!! 另外我自己需要赋值的网站(包含框架),连赋值都不行。
o:OleVariant;
i:integer;
Doc:IHTMLDocument2;
userinputelement,pwdinputelement,ValidateElement:ihtmlinputelement;
begin
Doc:=WebBrowser1.document as ihtmldocument2;
if doc=nil then exit;
userinputelement:=(doc.all.item('payFeeOnlineInfo.productNO',0) as ihtmlinputelement);
userinputelement.value:=ed_ltcode.Text;
userinputelement:=(doc.all.item('payFeeOnlineInfo.productNOAgain',0) as ihtmlinputelement);
userinputelement.value:=ed_ltcode.Text;
userinputelement:=(doc.all.item('payFeeOnlineInfo.checkCode',0) as ihtmlinputelement);
userinputelement.value:=ed_ltyz.Text;
userinputelement:=(doc.all.item('payFeeOnlineInfo.payFee',0) as ihtmlinputelement);
userinputelement.value:=ed_ltprice.Text; o:=doc.all.item('submit0',0);
state := 101;
o.click;
//o:=doc.all.item('payButton',0);
//o.click;end;
1. 利用GetActiveWindow取得当前输入框的的handle
2. 给输入框发送wm_gettext取得输入框的值或发送wm_settext设置输入框的值未测试过。你可以试试
1、通过IE句柄得到IHTMLDocument2接口
http://blog.csdn.net/lion_wing/archive/2006/05/26/756105.aspx
2、通过IHTMLDocumnet2得到网页源代码
http://blog.csdn.net/lion_wing/archive/2006/06/02/769742.aspx
On Error Resume Next
Dim Titles As String
Dim IEList As New SHDocVw.ShellWindows
Dim Doc
Dim i As Integer
Dim j As Integer
Dim LocalNames As String
Dim Name As String, Password As String, Security As String
'If FormType = 1 Then
'Name = "username"
'Password = "password"
'Security = "ekey"
' Else
Name = "idInput"
Password = "pwdInput"
'Security = "username5"
'End If
'If FormType = 1 Then
'Titles = "纵横天下官方网站 - 盛大网络"
'Else
Titles = "126网易免费邮--你的专业电子邮局"
'End If
'遍历当前浏览器窗口
j = IEList.Count
For i = 0 To j - 1
'找到需要的IE窗口
LocalNames = Left(IEList.Item(i).LocationName, Len(Trim(Titles)))
If LocalNames = Trim(Titles) Then
'获得浏览器文档对象,填写表单
Set Doc = IEList.Item(i).Document
Doc.body.All("" & Name & "").Value = Trim(Text1.Text) '用户名
Doc.body.All("" & Password & "").Value = Trim(Text2.Text) '密码
'Doc.body.All("" & Security & "").Value = Trim(Text3.Text) '密保
If Mode = 1 Then
Else
'直接提交网页
'If FormType = 1 Then
'Doc.Forms("login").Submit
'Else
Doc.Forms("loginBtn").Submit
'End If
End If
Command3.Enabled = True
Command4.Enabled = True
Exit Sub
End If
Next
MsgBox "登录入口未加载完毕,请稍候再试!", vbSystemModal + vbOKOnly + vbExclamation, "Error"
Command3.Enabled = True
Command4.Enabled = True
End Sub找了个vb的,用126测试,可以赋值,但是提交不执行!!!
另外我自己需要赋值的网站(包含框架),连赋值都不行。