網(wǎng)頁中的按鈕沒有句柄可言,只有控件id,你想要的到底是什么,找到按鈕模擬點(diǎn)擊按鈕?
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、湘東ssl等。為上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的湘東網(wǎng)站制作公司
找到按鈕不難,查找input,id是那個(gè)按鈕的話就用DOM獲取到,然后發(fā)送.click方法
也可以用附加js腳本的方式來實(shí)現(xiàn)點(diǎn)擊那個(gè)按鈕,js腳本里實(shí)現(xiàn)獲取那個(gè)按鈕并點(diǎn)擊
'創(chuàng)建一個(gè)列表框和一個(gè)按鈕
'API函數(shù)定義
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim s As Long
Dim a As String
a = Space(255)
s = GetWindow(Me.hwnd, GW_HWNDFIRST) '獲得句柄
GetWindowText s, a, 255 '獲得標(biāo)題
Dim ab As String * 255
GetClassName s, ab, 255 '獲得類名
Dim ClassName As String
ClassName = StripTerFlag(ab) 'StripTerFlag是一個(gè)自定義函數(shù),后面有代碼,用于去處結(jié)束符
If UCase(ClassName) = "NOTEPAD" Then
List1.AddItem a
List1.ItemData(List1.ListCount - 1) = s
End If
Do While s
DoEvents
s = GetWindow(s, GW_HWNDNEXT) '獲得句柄
GetWindowText s, a, 255 '獲得標(biāo)題
GetClassName s, ab, 255 '獲得類名
ClassName = StripTerFlag(ab)
If UCase(ClassName) = "NOTEPAD" Then
List1.AddItem a
List1.ItemData(List1.ListCount - 1) = s
End If
Loop
End Sub
Private Sub List1_Click()
MsgBox List1.ItemData(List1.ListIndex) '單擊列表框獲得句柄
End Sub
Dim hwnd0 As Integer
Dim hwnd11 As Integer
第二個(gè)是你要生成EXE后 運(yùn)行EXE
第三就是沒好像沒有文本框控件
先找到窗口的句柄,再來查找按鈕的句柄,如果按鈕有文本內(nèi)容,那就好辦,如果沒有,那建議你利用SPY++先來察看一下按鈕的類型,以此類型為查找參數(shù)多次調(diào)用FindWindowEx來查找,直到找到的的句柄和Spy++相同,那么這個(gè)按鈕就找到了。
按鈕類名同樣,但是你去遍歷的時(shí)候它的次序始終是固定的。通過id不可靠,有些有id但是有些id是0。
clswindow類,里面有個(gè)函數(shù)etElementHwndByClassName,可以得到指定的次序按鈕。加入你要處理的按鈕是在第二個(gè)次序,類名為Button,那么就用:GetElementHwndByClassName("Button",2),即可,
具體代碼:
Private Sub Command6_Click()
Dim w As New clsWindow
Dim i%
If w.GetWindowHwndByTitleEx("自動(dòng)化操作框架") 0 Then
i = i + 1
Do While w.GetElementHwndByClassName("ThunderCommandButton", i) 0'按次序遍歷
MsgBox w.GetElementHwndByClassName("ThunderCommandButton", i)'得到當(dāng)前次序按鈕的句柄
w.SetElementTextByClassName "ThunderCommandButton", "次序" i, i'設(shè)置按鈕文本
i = i + 1
Loop
End If
End Sub