本文介绍了打开网页浏览器,自动完成表单组件,并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在研究建立一个WPF / WinForms应用程序的方法,我们可以设置在内部: -

We are currently investigating a method of creating a WPF/winforms application that we can set up internally to :-

  1. 自动打开一个网页浏览器的新实例为predefined网址
  2. 与$ P $自动完成必填字段pdefined数据
  3. 在自动提交表单,等待下一个页面加载
  4. 与predefined数据自动完成所需的字段(第2页)
  5. 在自动提交表单,等待下一个页面加载(等)

经过一番调查,我们已经设法找到的唯一的事情就是通过开放的Web浏览器: -

after much investigation, the only thing we have managed to find is the opening up of a web browser via :-

对象o = NULL;

object o = null;

        SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
        IWebBrowserApp wb = (IWebBrowserApp)ie;
        wb.Visible = true;
        wb.Navigate(url, ref o, ref o, ref o, ref o);

任何意见/阅读建议将pciated如何完成这个过程AP $ P $。

Any advice / reading recommendations would be appreciated on how to complete the process.

推荐答案

我写了一个例子填充的元素在一个HTML页面。你必须做一些事情是这样的:

I wrote an example for filling in an element in a html page. You must do something like this:

WinForm的

public Form1()
        {
            InitializeComponent();
            //navigate to you destination
            webBrowser1.Navigate("https://www.certiport.com/portal/SSL/Login.aspx");
        }
        bool is_sec_page = false;
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (!is_sec_page)
            {
                //get page element with id
                webBrowser1.Document.GetElementById("c_Username").InnerText = "username";
                webBrowser1.Document.GetElementById("c_Password").InnerText = "pass";
                //login in to account(fire a login button promagatelly)
                webBrowser1.Document.GetElementById("c_LoginBtn_c_CommandBtn").InvokeMember("click");
                is_sec_page = true;
            }
            //secound page(if correctly aotanticate
            else
            {
                //intract with sec page elements with theire ids and so on
            }

        }

WPF

public MainWindow()
        {
            InitializeComponent();
     webBrowser1.Navigate(new Uri("https://www.certiport.com/portal/SSL/Login.aspx"));
            }
            bool is_sec_page = false;
            mshtml.HTMLDocument htmldoc;
            private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
            {
                htmldoc = webBrowser1.Document as mshtml.HTMLDocument;
                if (!is_sec_page)
                {
                    //get page element with id
                    htmldoc.getElementById("c_Username").innerText = "username";
                    //or
                    //htmldoc.getElementById("c_Username")..SetAttribute("value", "username");
                    htmldoc.getElementById("c_Password").innerText = "pass";
                    //login in to account(fire a login button promagatelly)
                    htmldoc.getElementById("c_LoginBtn_c_CommandBtn").InvokeMember("click");
                    is_sec_page = true;
                }
                //secound page(if correctly aotanticate
                else
                {
                    //intract with sec page elements with theire ids and so on
                }
            }

只是定位到特定的URL,并填写页面元素。

Just navigate to specific URL and fill page element.

这篇关于打开网页浏览器,自动完成表单组件,并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:03