Solved

VB.NET Webbrowser Click Submit Button.

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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