Solved

VB.NET Webbrowser Click Submit Button.

Posted on 2012-03-13
2
2,798 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

19 Experts available now in Live!

Get 1:1 Help Now