简体   繁体   English

打开chrome并自动填充窗体字段Windows窗体C#

[英]Open chrome and Auto fill the form fields windows form C#

I want to Open chrome and Auto fill the form fields windows form C#. 我想打开chrome,然后自动填充Windows C#窗体域。 automatically open a new google chrome web browser to a predefined URL automatically complete required fields with predefined data I don't want to open web within Form control WebBrowser. 自动将新的Google chrome网络浏览器打开到预定义的网址,并使用我不想在Form Control WebBrowser中打开Web的预定义数据自动完成必填字段。

If I try the below code it's not working. 如果我尝试以下代码,则无法正常工作。

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

You can do it the approach you have already started (without opening chrome and using the WebBrowser control) : 您可以按照已经开始的方法进行操作(无需打开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);

If you insist on using Chrome, you should use Chrome WebDrive 如果您坚持使用Chrome,则应使用Chrome WebDrive

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM