如何在vb.net windows窗体按钮控件中单击网页中的按钮

问题描述:

我有一个带有web浏览器控件和按钮的窗体。

当我点击windows窗体中的按钮时,需要点击网页上的按钮。



网页上按钮的源代码是



I have a windows form with a webbrowser control and button.
I need to click button on webpage when I click the button in windows form.

The source code of the button on the webpage is

<button class="bin btn-block btn-md btn-success btn-embossed" data-toggle="modal" onclick="formSubmitAjax();" >....</button>





我想我不能使用getelementbyid因为没有ID而且有onclick =formSubmitAjax();



I guess I cannot use getelementbyid as there is no ID and there is onclick="formSubmitAjax();"

你好
使用下面的代码,我在webbrowser控件中按设计加载www.google.com url,在windows窗体中单击按钮添加以下代码



Hi Use following code,i am load www.google.com url in webbrowser contorl by design,in windows form button click event add below code

if (webBrowser1.Url.Host.EndsWith("google.com")) {
    HtmlDocument doc = webBrowser1.Document;
    HtmlElement ask = doc.All["q"];
    HtmlElement lucky = doc.All["btnI"];
    ask.InnerText = "stackoverflow";
    lucky.InvokeMember("click");
  }





这时当你点击windows按钮时,它会自动在搜索栏中添加stackoverflow测试并点击搜索按钮google.com网站。



问候

Aravindb



Here when u click windows button it automatically add "stackoverflow" test in search bar and it click search button of google.com website.

Regards
Aravindb