Solved

VB.NET Webbrowser Click Submit Button.

Posted on 2012-03-13
2
2,861 Views
Last Modified: 2012-03-13
Hi there, I would like to know how to click submit button on the HTML form in a webbrowser control.

HTML FORM:

<form method="POST" action="login.php">
					<table border="0" cellpadding="4" cellspacing="1" class="w12">
						<tr>
							<td>Login:</td>
							<td>
								<input type="text" name="username" class="b12">
							</td>
						</tr>
						<tr>
							<td>Password:</td>
							<td>
								<input type="password" name="password" class="b12">
							</td>
						</tr>
						<tr>
							<td colspan="2" align="right">
								<input type="submit" value="Login">
							</td>
						</tr>
					</table>
				</form>

Open in new window


PS: I have no access to the page, so I cannot change the source code, it has to work with the one above.

Thanks
0
Comment
Question by:mropenmind
2 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 37715059
You should be able to find the element by it's type and then use InvokeMember for the click:
For Each b As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
    If b.GetAttribute("type") = "submit" Then
        b.InvokeMember("click")
    End If
Next

Open in new window


Note that if there are multiple forms with more than one submit, this would cause problems, in which case you can use a similar trick on the form itself (this is probably the better solution):

For Each b As HtmlElement In WebBrowser1.Document.GetElementsByTagName("form")
    If b.GetAttribute("action") = "login.php" Then
        b.InvokeMember("submit")
    End If
Next

Open in new window

0
 

Author Comment

by:mropenmind
ID: 37715126
Works like this:

WebBrowser1.Document.Forms(0).InvokeMember("submit")

but thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now