Selenium excels at things like this:Not well known by me, apparently.
Anyway, I've dealt with these "web testing/automation" tools before and they always come up short.
Excessively complicated to setup/use and limited functionality.
I'd love to be proven wrong.
That's why I am asking.
And, yes, the web page was fluff. I didn't dig in past the first page/screen, admittedly.
Anyway, I was going to suggest to OP using xdotool
to check the browser window title. That's how I usually go about this sort of task. Including, specifically, checking to see if a web page has logged you out since the last time you accessed the page; Specifically, what OP was looking for.
You write a web app, you need to QA test it. Unit testing, some load testing, functionality testing, etc. You do all of that with Selenium. It will interact with the browser as if it were the user using a keyboard and a mouse and also do some of the functionality of something like beautiful soup for checking that the output of the page contains the expected data based on the input it gave to the browser.
It takes time to learn how to do all that, but it should be relatively simple to get Selenium to check what the current browser URLs is and from there make it go to a login page, be it by clicking a login link/button on the currently open page or by just telling the browser to navigate to the login page.
Now, if OP is going to go through that trouble, it may be worth investigating which is better or will take less work, doing all of that with selenium, or change the web pages code so that it auto redirects to the login page.
I don't know what OP is doing, but it it is just using some web site running in the Pi, it should be possible to just change the website code to redirect after the token expires. If it's a 3rd party website, that's a whole other story and something like Selenium may be worth a look.
Statistics: Posted by memjr — Mon Jul 15, 2024 5:31 pm