【问题标题】:Open chrome and Auto fill the form fields windows form C#打开 chrome 并自动填充表单域窗体 C#
【发布时间】:2019-01-10 07:43:03
【问题描述】:

我想打开 chrome 并自动填充窗体字段窗体 C#。 自动打开一个新的谷歌浏览器到预定义的 URL 使用预定义数据自动填写必填字段 我不想在表单控件 WebBrowser 中打开网页。

如果我尝试下面的代码,它不起作用。

        System.Windows.Forms.WebBrowser webBrowser = new WebBrowser();
    HtmlDocument document = null;
    document=webBrowser.Document;
    System.Diagnostics.Process.Start("http://www.google.co.in");

【问题讨论】:

  • C#, selenium webdriver的可能重复
  • 请检查 selenium 或其他浏览器自动化。这个问题太笼统了。
  • 如果您可以更改网络服务器,一种廉价的解决方案是:更改目标 url 的参数,例如 aaa/someform?a=x&b=xx...,然后直接导航到该 url。但是如果你不能改变网络服务器,你将不得不学习如何使用套接字与 Chrome 通信,这与 Forms.WebBrowser 完全不同
  • 我无法处理查询字符串参数。网站源不在我手中。我想用特定的 URL 和自动填写表单打开新的独立 Chrome 浏览器。我不想在我的表单中使用 Windows 表单控件。

标签: c#


【解决方案1】:

您可以按照您已经开始的方法进行操作(无需打开 chrome 并使用WebBrowser 控件):

   System.Windows.Forms.WebBrowser webBrowser = new WebBrowser();
    webBrowser.DocumentCompleted += (s, e)=>{
     //add auto fill here ie:
     HtmlDocument doc = ((WebBrwoser)s).Document;
     var element = doc.GetElementById("email");
if(element!=null) element.SetAttribute("value", "AutoFillValue");
};
    webBrowser.Navigate(someUrl);

如果你坚持使用Chrome,你应该使用Chrome WebDrive

【讨论】:

    【解决方案2】:

    如果您知道表单字段名称,可以通过将它们作为查询字符串参数传递来预填充它们

    Process.Start("http://www.google.co.in?q=test");
    

    【讨论】:

    • 不,我不能处理查询字符串参数。我想自动填充网络表单中的数据。我只能访问 URL,
    • 添加正确的查询字符串参数将填充网络表单的字段
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多