Vbeginner.Net
Vbeginner.Net

Reputation: 11

How to fill a textbox from a website using webbrowser

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

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.

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.

Upvotes: 1

Views: 6391

Answers (3)

Milo
Milo

Reputation: 11

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

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

Hope this helps.

Upvotes: 1

Victor Zakharov
Victor Zakharov

Reputation: 26454

You need to be using a combination of WebClient and HtmlAgilityPack. See these examples:

Upvotes: 0

The_Black_Smurf
The_Black_Smurf

Reputation: 5269

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

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.

Upvotes: 0

Related Questions