C# 如何在第三方网站上单击网站提交按钮

C# 如何在第三方网站上单击网站提交按钮,c#,winforms,C#,Winforms,我想使用我的c#窗口应用程序单击网站提交按钮 <p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit"/></p></div> 首先,您告诉计算机按其ID抓取按钮,但不是使用ID,而是将类名放在ID所在的位置。我检查了该页面上的元素,没有看到该元素的“ID”。所以,让我们使用网站给我们的 这

我想使用我的c#窗口应用程序单击网站提交按钮

<p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit"/></p></div>

首先,您告诉计算机按其ID抓取按钮,但不是使用ID,而是将类名放在ID所在的位置。我检查了该页面上的元素,没有看到该元素的“ID”。所以,让我们使用网站给我们的

这将为您提供共享该类的所有元素的列表。所以不是

webBrowser2.Document.GetElementById("wpcf7-submit").InvokeMember("click");
请试一试

编辑:原来C#WebBrowser中没有GetElementsByClassName。另一种方法是识别按钮的值为“发送”。“value”是一个属性,可以在C#中访问。

您可以通过页面中的元素运行for循环,并检查哪些输入元素的值为“send”。这有点粗糙,但应该有用

//Create list of HtmlElement objects
        //Populate list with all elements with tag name 'input'
        HtmlElementCollection elementList = webBrowser2.Document.GetElementsByTagName("input");
        //loop through the items in elementList, match the one with value set to 'send'
        foreach (HtmlElement currentElement in elementList)
        {
            if (currentElement.GetAttribute("value") == "Send")
            {
                currentElement.InvokeMember("click");
            }
        }

此代码是否与WinForms的WebBrowser控件相关?您正在使用
MSHTML
(因为
HTMLInputElement
)?@Jimi我正在使用.net winform应用程序和web浏览器控件,是的,我正在使用MSHTML,知道如何在winform中单击此按钮吗是的,我知道。在
WebBrowser.DocumentCompleted
事件中,添加:
var browser=sender as WebBrowser;如果(browser.ReadyState!=WebBrowserReadyState.Complete)返回;var element=browser.Document.All.OfType().FirstOrDefault(elm=>elm.GetAttribute(“className”).Equals(“wpcf7表单控件wpcf7提交”);元素?.InvokeMember(“单击”)。当然,您必须填写表单的输入元素,提交才能实际工作。很抱歉,我无法看到此属性GetElementsByCassName我只能看到GetElementsByTagName,但这不起作用。我正在使用.NETWinFormapplication@PrernaPuri你是对的,我道歉。我已经编辑了我的代码。新的代码对我有效。
//Create list of HtmlElement objects
        //Populate list with all elements with tag name 'input'
        HtmlElementCollection elementList = webBrowser2.Document.GetElementsByTagName("input");
        //loop through the items in elementList, match the one with value set to 'send'
        foreach (HtmlElement currentElement in elementList)
        {
            if (currentElement.GetAttribute("value") == "Send")
            {
                currentElement.InvokeMember("click");
            }
        }