Skip to content
Advertisement

Slow scrolling down the page using Selenium

I’m trying to scrape some data from flight search page.

This page works this way:

You fill in a form and then you click on the button search – this is ok. When you click the button you are redirected to the page with results and here is the problem. This page is adding continuously results for example for one minute which is not a big deal – problem is to get all of these results. When you are in real browser, you have to scroll down the page and these results are appearing. So I’ve tried to scroll down using Selenium. It scrolls down at the bottom of the page probably so fast or it is a jump instead of scrolling that the page doesn’t load any new results.

When you are scrolling down slowly, it reloads results but if you do it very quickly it stops loading.

I’m not sure if my code helps to understand that so I’m attaching it.

JavaScript

So the main problem is in my opinion that it scrolls too fast to trigger new loading of the results.

Have you any idea how to make it work?

Advertisement

Answer

Here is a different approach that worked for me involving scrolling into view of the last search result and waiting for additional elements to load before scrolling again:

JavaScript

Notes:

  • you would need to figure out when to stop the loop – for example, at a particular len(results) value
  • wait_for_more_than_n_elements is a custom Expected Condition which helps to identify when the next portion is loaded and we can scroll again
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement