hey, i have this image in a webbrowser control, and want to click it. the code is : <INPUT class=IMAGE id=_ctl6__ctl0_Rate2 type=image alt="" src="http://.com/Rate2g.gif" border=0 name=_ctl6:_ctl0:Rate2>
how can i simulate a click?
Printable View
hey, i have this image in a webbrowser control, and want to click it. the code is : <INPUT class=IMAGE id=_ctl6__ctl0_Rate2 type=image alt="" src="http://.com/Rate2g.gif" border=0 name=_ctl6:_ctl0:Rate2>
how can i simulate a click?
Using the API Function called mouse_event you can simulate your click:
API Function:
The Constants:Code:Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
The LeftClick:Code:Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_MOVE = &H1
Code:Public Sub LeftClick() 'Programmatically click
LeftDown
LeftUp
End Sub
Public Sub LeftDown() 'MouseDown
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
End Sub
Public Sub LeftUp() 'MouseUp
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
'You can also use these for different mouse events:
Public Sub MiddleClick()
MiddleDown
MiddleUp
End Sub
Public Sub MiddleDown()
mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
End Sub
Public Sub MiddleUp()
mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
End Sub
Public Sub MoveMouse(xMove As Long, yMove As Long)
mouse_event MOUSEEVENTF_MOVE, xMove, yMove, 0, 0
End Sub
Public Sub RightClick()
RightDown
RightUp
End Sub
Public Sub RightDown()
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
End Sub
Public Sub RightUp()
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub
sorry, i'd like to minimize the program
you would like to minimize with a simulated click right?
not really
What are you trying to do then?, because you asked "how to simulate a click".
well, I found this code:
Public Sub SubmitByValue(www As WebBrowser, ByVal strValue As String)
'strValue is the Text displayed on the Submit Button
Dim aItem() As String
Dim iItem As Integer
Dim iChar As Integer
Dim dString As String
Dim i As Integer
On Error Resume Next
For i = 0 To www.Document.All.length - 1
dString = dString & CStr(i) & "-" & _
Trim(www.Document.All.Item(i).Value) & vbTab
Next i
aItem = Split(dString, vbTab)
For i = 0 To UBound(aItem)
iChar = InStr(1, aItem(i), strValue)
If iChar > 0 Then
iItem = CInt(Mid(aItem(i), 1, iChar - 2))
www.Document.All(iItem).Click
Exit For
End If
Next i
End Sub
it presses a command button in a webbrowser. But now it isn't a command button but an image I want to press
bump
You can try something like this:
VB Code:
Option Explicit Private Sub Form_Load() WebBrowser1.Navigate2 "http://www.vbforums.com" End Sub '------------------------------------------------------------------- Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _ URL As Variant) Dim i As Integer 'Wait till document has loaded If pDisp Is WebBrowser1.Application Then 'Loop through images For i = 0 To WebBrowser1.Document.Images.length - 1 If WebBrowser1.Document.Images.Item(i).src = _ "http://www.vbforums.com/images/misc/birthday.gif" Then WebBrowser1.Document.Images.Item(i).[b]Click[/b] 'Click on the image End If Next i End If End Sub