webBrower Button Click without element ID?
Posted
by
Jeremy
on Stack Overflow
See other posts from Stack Overflow
or by Jeremy
Published on 2010-12-29T18:49:22Z
Indexed on
2010/12/29
18:53 UTC
Read the original article
Hit count: 239
I'm working on a login system for a forum and trying to make it work via a c# .net form. I need to programitically click the login button on the forum with a webBrower control. So far I have this.
webPage page = new webPage();
page.URL = txtURL.Text;
page.Load(); //Load the text from the specified URL
WebBrowser browser = new WebBrowser();
browser.Document.GetElementById("navbar_username").SetAttribute("value", textBox1.Text);
browser.Document.GetElementById("navbar_password").SetAttribute("value", textBox2.Text);
HtmlElement el = browser.Document.All["btnI"];
if (el != null)
{
el.InvokeMember("click");
}
else
{
MessageBox.Show("There is an issue with the program");
}
The issue is that the login button on the page does not have an ID or any real information that can allow me to click on it. Does anyone have any suggestions? Here is the code for the login button.
<input type="image" src="images/loginbutton.png" class="loginbutton" tabindex="104" value="Log in" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s">
© Stack Overflow or respective owner