Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a page is loaded using selenium?

I am interacting with a database that returns the newspaper reports about a event using selenium. Every time I implement a search query, the database opens a new page and starts to load all newspaper reports about the event. The webpage has an element that reports the total number of relevant reports found. The number changes before the page is fully loaded.

My question is there a way to determine if the page is loaded. My current strategy is to check the number of total reports in a loop and decides the page is complete when two loops report the same number of total reports. I am not sure if this is a good strategy.

like image 951
Yan Song Avatar asked Oct 21 '25 04:10

Yan Song


1 Answers

My current strategy is to check the number of total reports in a loop and decides the page is complete when two loops report the same number of total reports. I am not sure if this is a good strategy.

It is.

There is no universal rule when "a page is loaded" in a sense that you can interact with it in an expected way and be able to control the desired elements. Checking the counter - how much results are loaded is a common condition to use for a "wait" - usually an Explicit Wait.

The results counter is especially commonly used when there is an "infinite" scroll pagination on a page - every time we scroll we check that the current results count became greater than when the before the scroll - this is an indication that a new portion of results arrived and we can scroll again.

like image 142
alecxe Avatar answered Oct 23 '25 18:10

alecxe