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.
You can use an action like this:
$this->getSession()->executeScript('window.scrollTo(0,0);');
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With