I just spent 2 hours trying to find out what was wrong with my code. Basically, here is what I did:
if (browser.DocumentText.Contains("Something"))
{
[do somwthing]
}
I rendered the page in the WebBrowser control just before running this command, so I know for sure the text is there, but it still returns false.
I did some debugging, and I found that browser.DocumentText contains some weird form of HTML.
Now I could iterate thru the labels in the document and get the text from there, but is there a way to do it by looking at the HTML?
Let me provide you a better way to do it, without using .DocumentText and having to parse all those strings, erk.
If wbMain is your WebBrowser1 control, do the following.
First, you need to get a ref to your element, lets say you want to access the first
<A>link, on your page, you can loop through all if you want.This is in VB, but its the same sort of thing in C#, just different syntax.
This will loop through all attributes and display it in a MSGBOX in a
name=valueformat.If you want to retreive it by name (attributes name) just call using
aElement.getAttribute("target")to retreive the target attributes value from the a Link.If you want to confirm you got the right object/element, just do a
aElement.outerHTMLto get the full HTML code for that element only.Since I am using a pre.NET version, feel free to change the declaration from HTMLAnchorElement to IHTMLAnchorElement if it gives you trouble, of course, you can just use IHTMLElement if you want to go through all elements on a page, then all you’ll need to do is wbMain.Document.All(0) for first element on a page, or loop until .All.length – 1 to go through all. Remember if you are using nested For loops, don’t use i twice, use j for one of them :).
Let me know if this answers your question or if there is more I can do to help you with your issue.