[Python] How to know if a page has failed to load while using Selenium/Python - Chrome/Edge?

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to program a bot using Selenium/Python - Chrome/Edge web driver that changes the section of a course that the university has assigned me to from my university's registration page. However, in the registration period, there are lots of people who are trying to add/drop courses or change sections; therefore, the site becomes overloaded with people, causing unpredictably long loading times for the registration website. The problem here is that sometimes the website does not load and gives an error or even worse, sometimes it looks like its loading, but the page is not actually loading and will fail to load after about 1-2 minutes. This means that the bot will probably waste lots of time trying to load a page that will not load in the end, and I would like to prevent this by refreshing the page if the program sees that the page will not load. My question is, is there any way to know if a page will load or will fail to load or has failed to load with Selenium Python? I know there is a "complete" condition for checking if the page has been successfully loaded; however, I haven't found a way to see if a page has failed to load etc. Also, the "loading" condition from my understanding, is not very reliable in my case since the program also does not know exactly what to look for to check if a page will actually load or is doing one of those "fake" loads I have talked about above, which will fail after some time. I should also add that I tried to use explicit wait - until and check if the login box is available to see if it would work; however, since the site's loading time is unpredictable during the registration period, it also does not work. Could anyone with knowledge in how sites actually load and knows when a site will load or fail could help me figure this out? P.S. I did not include any code here since the registration site is closed outside the registration period and the code is pretty much useless at the time that I'm asking this question.

    Continue reading...

Compartilhe esta Página