简体   繁体   English

c# - 在 WebBrowser 上选择特定的文本框并在其中写入

[英]c# - Select specific text boxes on WebBrowser and write in them

how would I select a specific text box on a web browser (the default c# webbrowser) and write a string in it?我如何在网络浏览器(默认的 c# webbrowser)上选择一个特定的文本框并在其中写入一个字符串? I have been thinking of webrequests but that may be illegal due to the amount of packets you will send to the host server.我一直在考虑 webrequests,但由于您将发送到主机服务器的数据包数量,这可能是非法的。

If you are just wanting to fill in a field, you need to use the DOM.如果您只是想填写一个字段,则需要使用 DOM。 Here are some examples that assume your browser is named browser and has navigated to google.com.以下是一些示例,假设您的浏览器名为browser并已导航到 google.com。

WPF WPF

     mshtml.IHTMLDocument2 htmlDoc = browser.Document as mshtml.IHTMLDocument2;
     ((mshtml.HTMLInputElement)htmlDoc.all.item("lst-ib")).value = "wpf web browser access dom";

WinForms窗体

     HtmlDocument htmlDoc = browser.Document;
     htmlDoc.All["lst-ib"].InnerText = "c# web browser access dom";

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

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