'How to assign HtmlDocument to a web browser, then interact with specific controls via GetElementById in c# / Console application
I have a requirement to navigate to a specific website, select a value from a drop down list, then click on a submit button. The solution has to be via a console app via c#.
So working backwards, I need to eventually be able to interact with controls like this:
html.GetElementById("shellmenu_0").InvokeMember("Click");
In order to work with html elements I need an HtmlDocument object. So as an example, the code below attempts to go to the Microsoft site and click a link to a new page. The code is as follows.
WebBrowser wb = new WebBrowser();
wb.AllowNavigation = true;
wb.Navigate("https://www.microsoft.com/en-us/?ql=4");
HtmlDocument document = wb.Document;
document.GetElementById("shellmenu_0").InvokeMember("Click");
I think I am on the right track, but I am hitting a null exception on the document. I must be missing a step to assign the website to the document somehow.
Any advice would be greatly appreciated. Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
