【问题标题】:C# - Pass string to textbox in web page using the webbrowser controlC# - 使用 webbrowser 控件将字符串传递到网页中的文本框
【发布时间】:2010-12-08 14:23:06
【问题描述】:

有没有办法在使用 webbrowser 控件时获取字符串的值并将其传递到网页中的文本框?

【问题讨论】:

    标签: c# string browser webpage


    【解决方案1】:
    HtmlDocument doc = this.webBrowser1.Document;
    doc.GetElementById("myId").SetAttribute("Value", "someValue");
    

    试试这个

    【讨论】:

    • 谢谢。另一个相关的小问题。我如何在网页中按下按钮?
    • 像这样调用点击..webBrowser1.Document.GetElementById("myBtn").InvokeMember("click");
    • 哎呀,打算更新这个。问完没多久我就知道了。感谢您的所有帮助。
    【解决方案2】:

    您可以在 C# 中为 WebBrowser 控件进行浏览器自动化。

    Here's the reference article 解释如何做到这一点。

    http://www.codeproject.com/KB/cs/mshtml_automation.aspx

    【讨论】:

    • 请注意,本文不讨论内置的 Windows.Forms.WebBrowser 控件
    • 仍然可以通过将 webBrowser .Docuemt.DomDocument 属性转换为 mshtml.HtmlDocumentClass 来将此方法与标准 WebBrowser 控件一起使用
    【解决方案3】:

    你可以这样做:

    String newValue = "Sample Text";
    HtmlElement txt = WebBrowser1.Document.GetElementById("ElementIdOnHtmlPage");
    txt.SetAttribute("value",newValue);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多