[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Click a button in webbrowser

Posted on 2010-01-06
8
Medium Priority
?
269 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:ansori
  • 4
  • 4
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26191883
That code is trying to find an <input> element with the "submit" name, and the element doesn't have a name.
0
 

Author Comment

by:ansori
ID: 26191919
so, what the solution?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26191968
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ansori
ID: 26195442
no, it have more than 6 input element and 2 form.

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26195604
Then, you can get the <input> elements in the collection, and loop through to find the element that you need.
0
 

Author Comment

by:ansori
ID: 26195621

<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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 26196230
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
 

Author Closing Comment

by:ansori
ID: 31673535
work, thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question