hey guys im really stuck, when i run y program if finds fields fill's them in and submits, but sometimes the page does not have them fields and i just want it to skip them if not found so it continues otherwise it crashes.

my e.g field:

WebBrowser1.Document.GetElementById("subject").SetAttribute("value", TextBox3.Text)


please help

Edited 4 Years Ago by daydie: n/a

Does it throw an Exception?

If so, wrap it in a try/catch block

try
{
   //reach for the element
}
catch(Exception exc) //or the specific error being thrown
{
   //take other action.
}

You could also do a scan of the page before you try to read its elements to see what's available.
I prefer that to putting an exception handler in logic processing.

Edited 4 Years Ago by thines01: clarity

where wud i put my code as i have 3 lines of subject n message n click

Inside of the try {}

Actually, you only need the GetElementById call inside the try{}.

Edited 4 Years Ago by thines01: n/a

tis code is saying it wrong

Try {
            Catch ex As Exception
                WebBrowser1.Document.GetElementById("subject").SetAttribute("value", TextBox3.Text)
                WebBrowser1.Document.GetElementById("message").SetAttribute("value", RichTextBox1.Text)
                WebBrowser1.Document.GetElementById("btnSubmit").InvokeMember("click")
                }
            End Try

begining of { says end of statement expected and at the end } says syntax error.

any advice?

thaks got it working,

Try 
                           WebBrowser1.Document.GetElementById("subject").SetAttribute("value", TextBox3.Text)
WebBrowser1.Document.GetElementById("message").SetAttribute("value", RichTextBox1.Text)
WebBrowser1.Document.GetElementById("btnSubmit").InvokeMember("click")
                Catch ex As Exception
            End Try
This question has already been answered. Start a new discussion instead.