Search code examples
phpsymfonyweb-scrapingscreen-scrapingsymfony-panther

How to scroll to element using Symfony Panther without executing javascript?


I want to scroll to an element using Symfony Panther but without using the javascript method.

Does anybody know a way to do that?

The javascript method is something like this:

<?php

// autoload here

$client = Client::createChromeClient();

$client->executeScript('document.getElementById("someElementId").scrollIntoView();');

Solution

  • Use the client that is the representations of the browser. For instance:

    $client = Client::createChromeClient();
    $client->getKeyboard()->pressKey(WebDriverKeys::PAGE_DOWN); 
    

    of course as you can interact with the mouse or keyboard to scroll down in the browser there are also other possibilities how can you do that. The PageDown is just an example

    There are many more interesting functions inside just check the sources