WebBrowser单击ComponentArt将不会导航/更新WebBrowser.Document [英] WebBrowser clicking a ComponentArt won't navigate/update the WebBrowser.Document

查看:62
本文介绍了WebBrowser单击ComponentArt将不会导航/更新WebBrowser.Document的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从C#应用程序中使用隐藏的浏览器导航到页面,单击链接并验证单击是否有效.
流量:
-导航至"http://mypage"
-单击一个链接,该链接的HTML代码为(调用ComponentArt CallBack):

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):

<div id="ctl00_ctl00_PlaceHolderMain_Colleague1_linkAdd" onclick="colleagueCallback.callback('SOMENAME'); return false;">
<a href="javascript:void(0)">Add colleague</a>
</div>


-等待点击以获取结果并更新页面
-确认点击有效

我的问题:
除非我调用WebBroser.Print()(我不需要,只是尝试了百万种方法来找出单击后发生的情况,只有打印"才能使单击完成),否则单击似乎并未完全完成.

该代码运行正常,可以正常工作,可以找到我要查找的标签,触发click事件(发生中间更改),但是回调未完成,因为仅使用WebBrowser即可完成.Print(),所有其他WebBrowser.Invalidate(),WebBrowser.Update(),WebBrowser.DocumentStream.Flush()或WebBroser.ResumeLayout()不会最终确定页面内的ASP回调...:


- 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 ...:

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();
}


之后,我要验证ComponentArt服务器的CallBack是否已更改标签之一,但仅获取了中间标签.我正在监视的更改是:


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:

<a href="javascript:void(0)">Add colleague</a>


会将中介更改为(在CallBack中添加添加逻辑时):


will change intermediary to (while making the add logic in the CallBack):

<img src="/images/loading.gif">


最后应更改为:


in the end should change to:

<br>Is your colleague</br>




任何人都知道WebBroser.Print()中正在发生什么事情,这使页面完全完成了回调吗?




Anyone knows what exaclty is going on in the WebBroser.Print() that makes the page fully complete the callback ?

推荐答案

如果您在ComponentArt ^ ]
You are more likely to get an answer if you ask your question on the ComponentArt site[^]


找出了问题所在.在验证期间,在InvokeMethod("click")之后使用Thread.Sleep()等待更新.如果WebBrowser的事件在导航过程中被暂停,则其事件看起来像被搞砸了. Application.DoEvents()无法恢复任何内容,以某种方式Print()和相关方法仍然不知道如何恢复.

我所做的是一个循环,一次又一次下载页面以确认更改是否发生,循环中再也没有睡眠.您可以使用信号量之类的东西在单独的线程中执行此操作……现在我不需要这种复杂性.
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.


这篇关于WebBrowser单击ComponentArt将不会导航/更新WebBrowser.Document的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆