Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom code project, WebBrowser related, can't find the elements of specific id in C#
    text
    copied!<p>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 <strong>Windows Form Application</strong> but in <strong>Console</strong> application it's showing me <em>'Object reference not set to an instance of an object'</em>. So far, by doing debugging, taking all the stuff from <strong>HTMLElementCollection</strong> to a <strong>var</strong> 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.</p> <p>The piece of code is provided below:</p> <pre><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></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload