Solved

VB.NET Webbrowser Click Submit Button.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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