Finding and clicking a button with no ID within html code in WebBrowser

后端 未结 2 1417
无人及你
无人及你 2021-01-05 22:14

I basically have a web-browser control that is going through and automatically completing some forms, it\'s been a breeze so far, however I\'ve gotten to a form that does no

相关标签:
2条回答
  • 2021-01-05 22:45

    something like that, maybe ?

    public void ClickButton(string type) {
        var button = myWebBrowser.Document.GetElementsByTagName("button")
                 .Cast<HtmlElement>()
                 .FirstOrDefault(m => m.GetAttribute("type") == type);
        if (button != null)
            button.InvokeMember("click"); 
    }
    

    Usage

    ClickButton("reset");
    ClickButton("submit");
    
    0 讨论(0)
  • 2021-01-05 22:50
    <td align="right" valign="middle" class="LeftSide" style="padding-right: 20; padding-top: 10;"><input type="submit" value="Submit" /></td>
    
    <td align="left" valign="middle" class="RightSide" style="padding-left: 20; padding-top: 10;" colspan="2"><input type="reset" value="Reset" /></td>
    
    
    HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("input");  
    foreach (HtmlElement el in elc)  
    {  
       if (el.GetAttribute("type").Equals("submit"))  
       {  
            el.InvokeMember("click");  
       }  
     }
    
    0 讨论(0)
提交回复
热议问题