Question Automating a Web Browser Window

Gufran

Member
Joined
Nov 3, 2011
Messages
6
Programming Experience
Beginner
Hi,
I am creating a small program that can automate the input to a web browser window, Like a survey filling bot but for my personal use,
All I want to know is there any way to simulate a Mouse click for a particular element in a web browser window so that It can submit the form automatically ?
Thanks :)
 
Hi,
I am creating a small program that can automate the input to a web browser window, Like a survey filling bot but for my personal use,
All I want to know is there any way to simulate a Mouse click for a particular element in a web browser window so that It can submit the form automatically ?
Thanks :)

Yes, you can do this by calling the .RaiseEvent("onclick") method against the object of type HtmlElement which hosts the HTML element you want to be "clicked". Kind regards!
 
Hi, Thanks for the hint.
Can you give me an example of this please ?
I have the process ID of the window I want to simulate a click into, say Google chrome or safari or any other browser. Just give me a little hint on it.
Thank you. :)
 
Consider the code below:

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http://www.somesite.com/someform.asp")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim MyURL As String = e.Url.ToString
        If MyURL <> "http://www.somesite.com/someform.asp" Then Exit Sub ' continues only if it reached the aimed site
        If WebBrowser1.Document Is Nothing Then Exit Sub ' continues only if a document is available
        If Not WebBrowser1.DocumentText.ToUpper.Contains("<HTML") Then Exit Sub ' continues only if the document contains HTML
        Dim MyDocument as HtmlDocument = WebBrowser1.Document
        Dim MyPageCode as String = MyDocument.DocumentText
        Dim MyElementInput1 As HtmlElement = MyDocument.GetElementsByTagName("INPUT").Item("entry")
        MyElementInput1.SetAttribute("value", "HTML tags")
        Dim MyElementInput2 As HtmlElement = MyDocument.GetElementsByTagName("INPUT").Item("search")
        MyElementInput2.RaiseEvent("onclick")
    End Sub

End Class


It depends on you having a form named Form1 containing a button control named Button1 and a webbrowser control named WebBrowser1

It would work if there was a site at the url "http://www.somesite.com/someform.asp" containig a HTML document with an INPUT tag (with name or id "entry") to receive a typed entry, and another INPUT (with name or id "search") to serve as button.

Your solution will depend mostly of the HTML content and Scripts at your target site, then your should previously know the page's code. You may reach them in your code with the .DocumentText propery stored at MyCodePage variable, as shown at the code above.

Hope this give you some clues to build on. Kind regards!
 
I am not using the webBrowser element but the Hooks to handle the web browser window. I have no control over the HTML content of the web browser Document, neither can write to it nor read from it. I only have the process id of the web browser and I am using it to handle the window, I can send keystrokes to it, I can send mouse clicks to it and I can send all other kind of input to it but I can not tinkle with the source codes of the page loaded into it.
to navigate, I have only one choice that is to simulate keyboard shortcuts for the window.
Now I want to click on a button, say the "Reply" button just beneath this post, How do I do that ? Is there any way ? any library, any concept or anything else ?
I am googling for a solution from last 15 days and all I found is a couple of users with same problem, a tons of unanswered post regarding similar question and no solution for my problem :uncomfortableness:

Since I can send keystrokes to the web browser window I thought of using "JavaScript Injection" to produce some kind of clicks on an element on web page, like:

VB.NET:
sendkeys.sendwait("^{L}")       'Send Ctrl+L to focus the address bar
sendkeys.sendwait("getElementById('SomeDivId').click()")         'Write Javascript to the address bar
sendkeys.sendwait("{ENTER}")     'Send 'ENTER' key to process the JavaScript

but definitely that is not a universal solution for a ton of reasons.

Any other possible concept you can think of ?
Please help me, I am totally lost :(
 
Back
Top