Reputation: 3197
I added Microsoft.mshtml as a reference to my project and came this far:
mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)webbrowser.Document;
string username = document.all["username"].GetAttribute("value");
but the 2nd line doesn't work. It says
"error CS0021: Cannot apply indexing with [] to an expression of type 'mshtml.IHTMLElementCollection'"
when hovering over "all". How do I access the elements in all?
Upvotes: 3
Views: 9836
Reputation: 21
After struggling for a couple of hours this solutions worked for me.
Dim document = DirectCast(MainBrowser.Document, IHTMLDocument3)
Dim formName = document.getElementsByName(AppSettings("myFormName")).OfType(Of IHTMLElement)().Select(Function(element) element.getAttribute("name")).FirstOrDefault()
Upvotes: 0
Reputation: 2433
Try this:
var document = (IHTMLDocument3) webbrowser.Document;
var value =
document.getElementsByName("username")
.OfType<IHTMLElement>()
.Select(element => element.getAttribute("value"))
.FirstOrDefault();
Upvotes: 5