0

要正确理解 - 这个问题有以下附件:

  1. 我有一个带有惰性加载器的页面 - 滚动时激活
  2. 惰性加载器由 JavaScript 处理
  3. 在将加载 100% 的页面末尾 - 您将看到一个必须激活的按钮。

以下是我尝试编写的示例:

    _WebContent.wbThread1.Focus();
    int length = 100;

    new Thread(() =>
        {
            for (int i = 0; i <= length; i++)
            {
                System.Windows.Forms.SendKeys.Send("{PGDN}");

                Thread.Sleep(new TimeSpan(0, 0, 3));
                st.Start();
            }
        }).Start();

一切都很顺利,但是处理事件SendKey有问题,我们需要为事件聚焦区域,万一失去焦点不会花费任何东西。


我开始在 MSDN 上查找信息,发现处理滚动非常有趣:

_WebContent.wbThread1.Document.Body.ScrollIntoView (true) / / allows scrolling to the top
_WebContent.wbThread1.Document.Body.ScrollIntoView (false) / / allows scrolling to the bottom
_WebContent.wbThread1.Document.Body.ScrollLeft = 100, / / sets the offset to the left
_WebContent.wbThread1.Document.Body.ScrollTop = 100, / / sets the upward shift
var rect = _WebContent.wbThread1.Document.Body.ScrollRectangle; / / returns the current position

这种功能组合并没有帮助。理论上代码是可行的,但实际上我在这个例子中没有成功。

处理滚动后的事件,我将执行类似的操作:

HtmlElementCollection _HtmlElementCollect = _WebContent.wbThread1.Document.GetElementsByTagName("A");
foreach (HtmlElement link in _HtmlElementCollect)
            {
                if (link.InnerText.Equals("Load More..."))
                    link.InvokeMember("Click");
            }

你有什么建议?我怎样才能最好地进行这种滚动?

4

1 回答 1

1

您可以使用滚动到底部

webCtrl.Document.Window.ScrollTo(0, Int32.MaxValue);
于 2012-12-25T13:59:20.930 回答