Question Web Browser trying to click button can't

NeedHelp

Member
Joined
Jun 5, 2011
Messages
7
Programming Experience
3-5
What I wanted:
1. I wanted app to goto web page - Which it does
2. Copy text from input box into search bar of imdb - Which it does
3. Then for app to automatically click button - Which it doesn't

Here is what app looks like
Looks_of_App.jpg

Here is code I have used in app


Here is code I have used in app

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Width = Me.Width
WebBrowser1.Height = Me.Height - 10
End Sub

Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
WebBrowser1.Navigate("http://www.imdb.com/")

End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim txt As HtmlElement = WebBrowser1.Document.GetElementById("q")
txt.SetAttribute("value", TextBox1.Text)

Dim btn As HtmlElement = WebBrowser1.Document.GetElementById("go")
btn.InvokeMember("click")

End Sub
End Class


Extra info:
I know howto click button when button has a name.
But in the case of IMDB.com they do not for their search button...
They have a class and a type but not a name


Code Below is source for search bar on IMDB's website

<input id="navbar-query" name="q" type="text" value="" autocomplete="off" /> <button class="nb_primary" type="submit">Go</button><noscript>  <a href="/search/">More</a></noscript>
<div id="navbar-suggestionsearch"></div>


How do i make it click search button automatically

Any Help is very appreciated thank you
 
Last edited:
Please don't post the same question more than once. If you post in the wrong forum then please use the Report Post icon to send a message to the moderators asking to move the thread. The two duplicates of this thread have been deleted.
 
What if you simply navigate straight to the search page:

Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
    WebBrowser1.Navigate("http://www.imdb.com/find?s=all&q=" & TextBox1.Text.Replace(" ","+"))
End Sub
 
Can't, need vb to click web button

Do you know of a way to do this like I can do with "GetElementById"

Thank you for you advice though, seriously appreciated
 
Try this:

Dim btn As HtmlElement = WebBrowser1.Document.GetElementsByTagName("button")(0)
btn.InvokeMember("click")
 
Looked great for the first second, then
Page kept continually refreshing - every half a second

(This occured when i used coding suggested above)
 
Right :) You will have to modify your code to keep the DocumentCompleted from firing your block of code every time:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) Handles WebBrowser1.DocumentCompleted
    If Not WebBrowser1.Url.ToString = "http://www.imdb.com/" Then Exit Sub
    Dim txt As HtmlElement = WebBrowser1.Document.GetElementById("q")
    txt.SetAttribute("value", TextBox1.Text)

    Dim btn As HtmlElement = WebBrowser1.Document.GetElementsByTagName("button")(0)
    btn.InvokeMember("click")
End Sub
 
Back
Top