【问题标题】:webBrower Button Click without element ID?web浏览器按钮单击没有元素ID?
【发布时间】:2011-06-01 05:03:23
【问题描述】:

我正在开发一个论坛的登录系统,并试图通过 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">

【问题讨论】:

    标签: c# login browser system


    【解决方案1】:

    你可以提交表单吗?该页面上还有更多按钮吗?

    【讨论】:

      【解决方案2】:

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

      遍历所有输入按钮并找到具有accesskey 属性设置为s 的按钮。这将是您的提交按钮。

      使用 jQuery,您将使用以下命令来选择此元素:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-08-24
          • 2014-10-02
          • 2015-02-26
          • 2011-11-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多