vb.net 如何使用 webbrowser 从网站填充文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20723382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:13:42  来源:igfitidea点击:

How to fill a textbox from a website using webbrowser

vb.netvisual-studio-2010visual-studio-2013

提问by Vbeginner.Net

I'm new at Visual Basics and I'm trying to fill the forms of the following website:

我是 Visual Basics 的新手,我正在尝试填写以下网站的表格:

http://www3.dataprev.gov.br/cws/contexto/hiscre/

http://www3.dataprev.gov.br/cws/contexto/hiscre/

I tried using this line of code:

我尝试使用这行代码:

WebBrowser1.Document.GetElementById("nome").SetAttribute("Value", "Test")

However, whenever I try I got the following error:

但是,每当我尝试时,都会出现以下错误:

A first chance exception of type 'System.NullReferenceException' occurred.

发生了“System.NullReferenceException”类型的第一次机会异常。

I would appreciate if someone could help me to accomplish this, it would save me a lot of time if I could automate this task.

如果有人可以帮助我完成此任务,我将不胜感激,如果我可以自动执行此任务,我将节省大量时间。

Thank you in advance, Daniel.

提前谢谢你,丹尼尔。

回答by Milo

WebBrowser1.Document.GetElementById("nome").InnerText = Test

That will select the input named "nome" and fill it with the text "Test"

这将选择名为“nome”的输入并用文本“Test”填充它

Hope this helps.

希望这可以帮助。

回答by Neolisk

回答by The_Black_Smurf

According to Microsoft documentation, the SetAttribute function your are using is case sensitive.

根据Microsoft 文档,您使用的 SetAttribute 函数区分大小写。

You'll need to replace "Value" for "value".

您需要将“值”替换为“值”。

WebBrowser1.Document.GetElementById("nome").SetAttribute("value", "Test")

However, the kind of error message you are getting seems to occur before the call to the SetAttribute function. Go in debug mode and make sure that every objects used before the SetAttribute function are not null.

但是,您收到的这种错误消息似乎发生在调用 SetAttribute 函数之前。进入调试模式并确保在 SetAttribute 函数之前使用的每个对象都不为空。