scoosteDusy
New Member
I've been working on a C# based web-browser related program on a console project. Now, here's a piece of code that is working in Windows Form Application but in Console application it's showing me 'Object reference not set to an instance of an object'. So far, by doing debugging, taking all the stuff from HTMLElementCollection to a var by the elementId, it's showing False, which means there's no such id inside the HTML. Now, this code is not wrong cause the same code is working perfectly inside the Windows Form Application. I hope you understand. A little help on this will be appreciated! Thanks.The piece of code is provided below:\[code\]if (browser.ReadyState == WebBrowserReadyState.Complete){ //Putting the values inside the boxes browser.Document.GetElementById("project_title").SetAttribute("value", projectTitle); browser.Document.GetElementById("article_title").SetAttribute("value", title); browser.Document.GetElementById("article_content").SetAttribute("value", content); browser.Document.GetElementById("article_tags").SetAttribute("value", tags); browser.Document.GetElementById("article_url_1").SetAttribute("value", url); browser.Document.GetElementById("article_keyword_1").SetAttribute("value", keywords); browser.Document.GetElementById("article_url_2").SetAttribute("value", url2); browser.Document.GetElementById("article_keyword_2").SetAttribute("value", keywords2); browser.Document.GetElementById("article_url_3").SetAttribute("value", url3); browser.Document.GetElementById("article_keyword_3").SetAttribute("value", keywords3); HtmlElementCollection lastElementCollection = browser.Document.All; foreach (HtmlElement webpageelement in lastElementCollection) { if (webpageelement.GetAttribute("value").Contains("Submit")) webpageelement.InvokeMember("click"); } Console.WriteLine("Please wait for 5 second(s)."); Thread.Sleep(5000); Console.WriteLine("Post has been submitted successfully!");}\[/code\]