donetbrowser 如何从 Dotnetbrowser 获取发布的表单数据?

donetbrowser HOWTO get posted form data from a Dotnetbrowser?

我需要帮助才能将表单数据发布到 Dotnet 浏览器。 其实我想在一个按钮上添加一个监听事件,当这个按钮被点击时,所以我得到了数据,例如:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <h1>Hello!!!</h1><br>
    <form
      id="formTrying"
      method="post"
      action="http://localhost/MyWebSite/MyMvcView?MyQueryStringParam1=something&Param2=something"
    >
      <input name="txtSomething" type="text" value="Trying something..."><br>
      <input type="submit" value="Submit...">
    </form>
  </body>
</html>

当我点击提交按钮时,我从 "txtSomething" 中获取值。 或者当 dotnetbrowser 检测表单提交时,我从 "txtSomething".

获取值

提前致谢。 ;)

您可以尝试为相应的 DOM 元素注册一个 OnClick 事件侦听器,以便收到有关点击的通知。

对于您的情况,可以如下所示完成:

browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e)
{
    if (e.IsMainFrame)
    {
        DOMDocument document = e.Browser.GetDocument();
        List<DOMNode> inputNodes = document.GetElementsByTagName("input");
        DOMInputElement submitElement = (DOMInputElement)inputNodes.LastOrDefault();

        DOMEventHandler domEvent = delegate (object s, DOMEventArgs args)
        {
            //Obtain the value of the txtSomething field
            DOMInputElement txtSomethingElement = (DOMInputElement)document.GetElementByName("txtSomething");
            string value = txtSomethingElement.Value;
            Console.Out.WriteLine("txtSomething value = " + value);
        };

        submitElement.AddEventListener(DOMEventType.OnClick, domEvent, false);
    }
};
browser.LoadHTML(@"<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
  <body>
    <h1>Hello!!!</h1><br>
    <form
      id='formTrying'
      method='post'
      action='http://localhost/MyWebSite/MyMvcView?MyQueryStringParam1=something&Param2=something'
    >
      <input name='txtSomething' type='text' value='Trying something...'><br>
      <input type='submit' value='Submit...'>
    </form>
  </body>
</html>");

下面的文章详细解释了如何注册一个DOM事件监听器: https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110034-listening-to-dom-events

此外,还有一篇文章介绍了如何以编程方式设置表单字段的值:https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110038-setting-input-field-value-working-with-form .示例中的 ValueChecked 属性是读写属性,对应于 JavaScript 中可用的 valuechecked 属性。