如何修复WatiN OutOfMemoryException

本文关键字:OutOfMemoryException WatiN 何修复 | 更新日期: 2023-09-27 18:18:51

我正在使用WatiN(大约3000)迭代一个非常大的div列表,并且我得到错误:

A first chance exception of type 'System.OutOfMemoryException' occurred in WatiN.Core.dll
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at WatiN.Core.UtilityClasses.UtilityClass.TryFuncFailOver[T](DoFunc`1 func, Int32 numberOfRetries, Int32 sleepTime)
   at WatiN.Core.Native.InternetExplorer.IEElement.GetWithFailOver[T](DoFunc`1 func)
   at WatiN.Core.Native.InternetExplorer.IEElement.GetAttributeValue(String attributeName)
   at WatiN.Core.Element.GetAttributeValueImpl(String attributeName)
   at WatiN.Core.Component.GetAttributeValue(String attributeName)
   at WatiN.Core.Element.get_OuterHtml()
   at WatiN.Core.Document.get_Html()

当点击一个div然后得到浏览器的html。

有人知道如何解决内存问题吗?我希望我可以使用不同的功能或以某种方式分割页面。也许我需要使用WatiN

以外的东西

代码是:

 foreach (Div d in browser.Divs)
                    {
                        try
                        {
                            d.Click(); // click div
                            System.Threading.Thread.Sleep(250); //wait for new data to load
                            string url = "";
                            if (browser.Html.Contains("http://www.google.com/url?")) // check if an external link exists on the page - this causes the memory exception
                            {

谢谢你的帮助

克里斯

如何修复WatiN OutOfMemoryException

首先在等待页面时不要用户线程休眠,您有browser.WaitForComplete()

如果你想检查链接是否带你到特定的页面,你可以直接检查浏览器的url,像这样:browser. url . contains ("address")…

在这种情况下,这是Internet Explorer的问题,因为它使用的内存量超过了1GB,可能达到了32位。net对象的限制。

在我的情况下,在64位系统上运行"修复"(或者更确切地说,延迟)这个问题。

相关文章:
  • 没有找到相关文章