简体   繁体   中英

how do I get contents from page updated by ajax?

I'm using a WebBrowser in my application. When I click on submit button, some javascript runs and by using ajax the page get some new contentes that I want to save. But it doesn't work, if I do:

btn.InvokeMember("click"); // send the form and then runs AJAX
Thread.Sleep(1000 * 10); // it doesn't take so long... but about 1000
var d = browser.Document.GetElementsByTagName("p"); // p is null

but if I call var d = browser.Document.GetElementsByTagName("p"); from a button click it works ( p isn't null ) even if I remove Thread.Sleep(1000 * 10);

I have no idea why. It is not because the p HTML tags wasn't loaded yet because the click on the button even without the Thread.Sleep() call take much less time but I get the HTML elements.

I hope this is clear but if it isn't tell me and I'll try clarify.

Try timer instead of sleep and check browser. ReadyState == WebBrowserReadyState.Complete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM