Click a button in webbrowser

i want click a button in this form

i am trying to  use this : WebBrowser1.Document.All("submit").InvokeMember("click")
but it not work
and get error message

"NullRefferenceException was unhandled"
<form method="POST">
    		<div class="txtarea">
  			<input id="id_url" name="url" class="txt filled" type="text" value="stick the web address here" />
  		</div>
  		<input class="big-red" type="submit" value="Submit URL &raquo;" />
  	</form>

Open in new window

ansoriAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
Try something like this:


Dim inputElementList As HtmlElementCollection = Me.WebBrowser21.Document.GetElementsByTagName("input")

        For Each element As HtmlElement In inputElementList
            Dim type As String = element.GetAttribute("type")

            If type = "submit" Then
                element.InvokeMember("click")
                Exit For
            End If
        Next

Open in new window

0
 
Bob LearnedCommented:
That code is trying to find an <input> element with the "submit" name, and the element doesn't have a name.
0
 
ansoriAuthor Commented:
so, what the solution?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Bob LearnedCommented:
If you know that there is only 1 <input> element, you could use the Document.GetElementsByTagName method to get the <input> elements:

Example:

        Dim inputElementList As HtmlElementCollection = browser.Document.GetElementsByTagName("input")
0
 
ansoriAuthor Commented:
no, it have more than 6 input element and 2 form.

0
 
Bob LearnedCommented:
Then, you can get the <input> elements in the collection, and loop through to find the element that you need.
0
 
ansoriAuthor Commented:

<form class="searchbox" action="/search/" method="get">
<input class="txt filled" style="vertical-align:middle" type="text" name="q" value="Look it Up. I bet we have it!" />
<input style="vertical-align:middle" type="image" src="http://o.aolcdn.com/propeller/images/searchbox-btn-2.gif" />
</form>

<form method="POST">
  	
<div class="txtarea">
<input id="id_url" name="url" class="txt filled" type="text" value="stick the web address here" />

</div>
<input class="big-red" type="submit" value="Submit URL &raquo;" />
</form>

Open in new window

0
 
ansoriAuthor Commented:
work, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.