Click here to Skip to main content
16,017,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to navigate to a page with a hidden browser from within a C# application, click on a link and verify the click worked.
Flow:
- navigate to "http://mypage"
- click on a link, the link HTML code is (calling a ComponentArt CallBack):
XML
<div id="ctl00_ctl00_PlaceHolderMain_Colleague1_linkAdd" onclick="colleagueCallback.callback('SOMENAME'); return false;">
<a href="javascript:void(0)">Add colleague</a>
</div>

- wait for the click to get the result and update the page
- verify the click worked

My problem:
The click does not seem to fully complete, unless I call the WebBroser.Print() (which I do not need, just tried a million ways to figure out what is going on after the click, only Print is making the click complete).

The code, which works absolutely fine, navigate is working, it can find the tags I am looking for, the click event is firing (I get an intermediary change), but the callback does not complete, as it turns out only using the WebBrowser.Print(), all the other WebBrowser.Invalidate(), WebBrowser.Update(), WebBrowser.DocumentStream.Flush() or WebBroser.ResumeLayout() won't finalize the ASP callback within the page ...:

C#
tempIE = new WebBrowser();
tempIE.Navigate("http://mypage");
while (tempIE.ReadyState != WebBrowserReadyState.Complete)
{
      Application.DoEvents();
}
tempIE.AllowNavigation = true;
HtmlElement addDivTag = tempIE.Document.GetElementById("ctl00_ctl00_PlaceHolderMain_Colleague1_linkAdd");
if (addDivTag == null)
    throw (new Exception("Session.FollowPerson: could not find the Add tag"));
if ( addDivTag.FirstChild == null )
    throw (new Exception("Session.FollowPerson: could not find the add link"));
addDivTag.FirstChild.InvokeMember("click");
while (tempIE.ReadyState != WebBrowserReadyState.Complete)
{
    Application.DoEvents();
}

After this I am verifying if one of the tags has been changed by the ComponentArt server CallBack but only getting the intermediary tag. The change I am monitoring is:
XML
<a href="javascript:void(0)">Add colleague</a>

will change intermediary to (while making the add logic in the CallBack):
XML
<img src="/images/loading.gif">

in the end should change to:
XML
<br>Is your colleague</br>



Anyone knows what exaclty is going on in the WebBroser.Print() that makes the page fully complete the callback ?
Posted
Comments
Henry Minute 9-Nov-10 9:39am    
OK.

Maybe another ComponentArt user has had similar problems, there are likely to be more of them hanging about on their site than here. So why not ask there as well? :)
Olics 10-Nov-10 2:50am    
have added the question on their forum as well, <a href="http://www.componentart.com/community/forums/t/62131.aspx">http://www.componentart.com/community/forums/t/62131.aspx</a>
Still just to clarify further, this is not about implementing the CallBack, but just using a WebBrowser to click a link on a page ... which happens to be a callback.
Am mostly interested if there is anything else to be done after I click, some kind of flush, update, rebind ... etc

Figured out the issue. During validation, after the InvokeMethod("click") used Thread.Sleep() to wait for the update. Looks like WebBrowser's events get screwedup if its thred is suspended during navigation. Application.DoEvents() are not able to recover anything, somehow the Print() and related methods do, have still no idea how.

What I did is a loop to download separately the page again and again to validate the change happen, no sleeps in the loop anymore. You could do it in separate threads with a semaphor or something ... no such complexity needed for me now.
 
Share this answer
 
You are more likely to get an answer if you ask your question on the ComponentArt site[^]
 
Share this answer
 
Comments
Olics 9-Nov-10 9:35am    
But the whole logic works just fine and as needed, except I need to Print() the document, which brings some kind of closure/flush/finalization to the WebBrowser. I certainly don't really need to print these pages ... is just what I have found so far.
It looks to me as a WebBrowser issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900