webBrowser按钮单击没有元素ID?

时间:2010-12-29 18:49:23

标签: c# login browser system

我正在研究论坛的登录系统,并尝试通过c#.net表单使其工作。我需要通过webBrower控件以论文方式点击论坛上的登录按钮。到目前为止,我有这个。

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");
}

问题是页面上的登录按钮没有ID或任何可以让我点击它的真实信息。有没有人有什么建议?这是登录按钮的代码。

<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">

4 个答案:

答案 0 :(得分:2)

你能提交表格吗?该页面上还有更多按钮吗?

答案 1 :(得分:1)

您在输入按钮上有一个accesskey属性,该属性在页面中是唯一的。

循环浏览所有输入按钮,找到accesskey属性设置为s的按钮。这将是您的提交按钮。

使用jQuery,您将使用以下内容来选择此元素:

$('input[accesskey="s"]')

答案 2 :(得分:0)

你可以使用webBrowser1.Document.GetElementsByTagName("input")左,而不是你可以遍历每个HTMLElement并查找element.innerText == "Log in",而不是你的按钮......

答案 3 :(得分:0)

您可以尝试在没有浏览器控件的情况下提交POST。

How to login to HTML form using POST vars in C# (.NET)?

相关问题