如何在 behat 中使用 scrollTop?

How to use scrollTop in behat?

我有一个页面,当我进入该页面时,它只会显示下面的部分,所以我想向上滚动以单击 page.How 顶部存在的元素之一,我可以实现吗,我试过如下但它不工作。

$this->getSession()->wait(5000, "jQuery('#page').animate({scrollTop: '-500px'}, 300)"); 

提前致谢。

您可以使用这样的操作:

$this->getSession()->executeScript('window.scrollTo(0,0);');

使用以下函数,您可以滚动到页面的任何 element/area: 场景:

/** * @Given /^I 滚动到 x "([^"])" y "([^"])" 页面坐标 $/ */

public function iScrollToXYCoordinatesOfPage($arg1, $arg2)
{

    try {
        $this->getSession()->executeScript("(function(){window.scrollTo($arg1, $arg2);})();");
    }

    catch(Exception $e) {
        throw new \Exception("ScrollIntoView failed");
    }
}

本例中的参数为“0”和“0”