gpt4 book ai didi

c# - 打开网络浏览器,自动完成表单组件并提交

转载 作者:太空狗 更新时间:2023-10-29 19:50:44 25 4
gpt4 key购买 nike

我们目前正在研究一种创建 WPF/winforms 应用程序的方法,我们可以在内部将其设置为:-

  1. 自动将网络浏览器的新实例打开到预定义的 URL
  2. 使用预定义数据自动完成必填字段
  3. 自动提交表单并等待下一页加载
  4. 使用预定义数据自动完成必填字段(第 2 页)
  5. 自动提交表单并等待下一页加载(等等)

经过大量调查,我们唯一设法找到的是通过以下方式打开网络浏览器:-

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);

如有任何关于如何完成流程的建议/阅读建议,我们将不胜感激。

最佳答案

我写了一个在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 并填写页面元素。

关于c# - 打开网络浏览器,自动完成表单组件并提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15447864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com