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

Recommended Answers

All 6 Replies

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.

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{}.

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

Thanks and sorry for the syntax.
My hands type C# by default :|
...but you got it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.