Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use scrollTop in behat?

I have a page, when I enter into that page it will show below part only, so I want to scroll up to click one of the element present in the top of the page.How can I achieve that,I tried like below but its not working.

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

Thanks in advance.

like image 617
Suraj Avatar asked Dec 05 '25 06:12

Suraj


2 Answers

You can use an action like this:

$this->getSession()->executeScript('window.scrollTo(0,0);');
like image 160
lauda Avatar answered Dec 08 '25 02:12

lauda


With the following function, you can scroll to any element/area of a page: Scenario:

/** * @Given /^I scroll to x "([^"])" y "([^"])" coordinates of page$/ */

public function iScrollToXYCoordinatesOfPage($arg1, $arg2)
{

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

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

The parameters in this case would be '0' and '0'

like image 41
Shweta Sharma Avatar answered Dec 08 '25 00:12

Shweta Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!