f0rdmstang
asked on
Simulate Mouse Click
I have written my code to determine where the mouse needs to go on the screen but I have been unable to make it click. I need it have it click on a specific button or field that I have identified in a web browser
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
well I though I had. I'm using a webbrowser embeded in my VB.net app and I'm trying to find the exact XY where it is located on the screen. for example the ID of the HTMLELEMENT would be "SubmitButton"
You could try clicking on using the WebBrowser itself.
Something like...
WebBrowser.Document.All.It em("Submit Button").C lick()
Something like...
WebBrowser.Document.All.It
ASKER
Due to some weirdness messing with the site I need to navigate I can not simple just send a click to the element as for some reason it doesn't work eventhough I simple mouse click (manually) does. What I need is the XY coordinates of it. I'm trying to work through HTMLELEMENT.parent and grab the XY of OffsetRectangle but it doesn't seem to be giving me the corrent coordinates in conjuntion with the me.top, me.left and webbrowser.location.x, webbrowser.location.y Any and all help is greatly appreciated.
I don't have much experience working with HTML objects unfortunately. I would post another question and ask how to get the screen coordinates of a button in a web page.
Which place do you put the coordinates in this code?
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, _
ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, _
ByVal dwExtraInfo As Integer)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Sub LeftMouseClick(ByVal x As Integer, ByVal y As Integer)
Cursor.Position = New Point(x, y)
mouse_event(MOUSEEVENTF_LE FTDOWN, x, y, 0, 0)
mouse_event(MOUSEEVENTF_LE FTUP, x, y, 0, 0)
End Sub
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, _
ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, _
ByVal dwExtraInfo As Integer)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Sub LeftMouseClick(ByVal x As Integer, ByVal y As Integer)
Cursor.Position = New Point(x, y)
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_LE
End Sub
You just call LeftMouseClick() and pass in the coords...
LeftMouseClick(500, 250)
LeftMouseClick(500, 250)
ASKER