我们目前正在研究一种创建
WPF / winforms应用程序的方法,我们可以在内部设置它:
>自动将Web浏览器的新实例打开到预定义的URL
>使用预定义数据自动填写必填字段
>自动提交表单并等待下一页加载
>使用预定义数据自动填写必填字段(第2页)
>自动提交表单并等待下一页加载(等)
经过多次调查,我们唯一能找到的就是通过以下方式打开网络浏览器: –
object o = null; SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer(); IWebBrowserApp wb = (IWebBrowserApp)ie; wb.Visible = true; wb.Navigate(url,ref o,ref o);
任何建议/阅读建议将不胜感激如何完成该过程.
解决方法
我写了一个例子来填充html页面中的元素.你必须做这样的事情:
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并填充页面元素.