目录
1.在已经打开的窗口中,找到百度的窗口(【百度一下,你就知道】)
■前言
从2022年6月15日起,
微软将终止IE浏览器服务支持 。
而VBS并不支持,Edge,Chrome等浏览器。
【IE不能使用后】使用Chrome插件,自定义JS插件操作浏览器
■举几个简单VBS操作IE的例子
1.在已经打开的窗口中,找到百度的窗口(【百度一下,你就知道】)
输入abc,
点击【百度一下】按钮
AutoSetting()
Function AutoSetting()
msgbox "111"
' get Operate window
Dim objPage
Set objPage = GetObj()
msgbox "222"
Dim entry
Set entry = objPage.document.getElementById("kw")
msgbox "333"
entry.Focus
entry.Value = "abc"
' when element no Id and Name , Use this
Dim objs
Set objs = objPage.document.getElementsByTagName("button")
If objs Is Nothing then
MsgBox "No Page Opened"
WScript.Quit
End IF
For Each obj In objs
If obj.innerText = "百度一下" Then
obj.Focus
obj.Click
'obj.Value
WScript.Sleep(70)
Set obj = Nothing
Exit For
End If
Next
End Function
Function GetObj()
Dim objWindow
Set objShell = CreateObject("Shell.Application")
For Each objWindow In objShell.Windows
If InStr(objWindow.LocationName,"百度一下,你就知道") Then
' Wait the page load completed
Do Until objWindow.document.ReadyState = "complete"
WScript.Sleep(70)
Loop
' set the return Object
Msgbox "Find"
Set GetObj= objWindow
' clear var
Set objShell = Nothing
Exit Function
End If
Next
' when Not Find
Msgbox "Not Find"
Set objShell = Nothing
Set GetObj= Nothing
End Function
---
其他获取元素操作
document.getElementById("XXXX").Value = "11111";
document.getElementsByName("commit")[0].Click;
document.forms[0].submit();
===