1

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.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Vbeginner.Net
  • 11
  • 1
  • 4

3 Answers3

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

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

Hope this helps.

Milo
  • 11
  • 1
0

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.

The_Black_Smurf
  • 5,178
  • 14
  • 52
  • 78
  • I read the documentation you linked above, but actually it is saying that "GetAttribute" and "SetAttribute" are case-insensitive. About checking the objects, I couldn't do that properly due to my inexperience. – Vbeginner.Net Dec 22 '13 at 00:57
  • Right click on your line of code and look for the Insert Breakpoint option. If you need to, find a tutorial about debuging because this is skill you will have to master sooner or later. – The_Black_Smurf Dec 22 '13 at 13:19
0

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

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151