webbrowser control

J

jaroslaw.pawlak

Hello, I'm trying to automate webbrowser using webbrowser control.
I have problem with pages using ajax, as when LoadComplete event is
executed, ajax part is not yet loaded, and after it is loaded -
webbrowser does not throw next complete event. How should I use
webbrowser control in order to get document with dom uptated with the
ajax part?.
Thanks in advance for any ideas
Jarek
 
B

Bim Jeam

Don't know if this is exactly what you're after but (providing I know the
target's ID or some other characteristic) I do it like this ...



// Get the target



(e.g)



HtmlElement target =
_webBrowser.Document.GetElementById("somedivthatwillbepopulatedbytheajaxrequest");



if (target != null)

{

target.AttachEventHandler("onpropertychange", new EventHandler(handler));

}



The event will fire whenever the element is (re)populated with HTML so all
you do is implement the handler so you can check the InnerHTML or InnerText
or whatever it is you need to do, and do it to your hearts content



(e.g)



private void handler(Object sender, EventArgs e)

{

HtmlElement div =
_webBrowser.Document.GetElementById("somedivthatwillbepopulatedbytheajaxrequest");

if (div == null) return;

String x = div.InnerHtml; // etc

if (!x.Equals("Loading...", StringComparison.InvariantCultureIgnoreCase))

{

// Now the element has been populated, do something

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top