Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99411

Methods to refresh browser page?

$
0
0

I just want to refresh a browser page for my smart mirror application! A PIR sensor detects a person and then the python scripts toggles the display ON - when it does it should also refresh the browser page(or alternatively close it and reopen) so my expressjs(server)/reactjs(frontend) application fetches new data. So I googled and tried out different methods over the course of several day (and I still didn't find a working solution!)

1.

import webbrowser
import os
webbrowser.open('localhost:3000', new=1) 
//later on when PIR sensor toggles display OFF
//os.system("taskkill /f /im  /usr/bin/firefox.exe") //uncomment once open function works..

Problem here: webbrowser.open literally does nothing, it does not even throw any errors. I wait and wait..

2.

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r"/usr/local/bin/geckodriver.exe")
driver.get('localhost:3000)
//later on when PIR sensor toggles display OFF 
//driver.close()
//alternatively if browser window is already open
//driver.refresh()

problem here: I get the error "Message: 'geckodriver.exe' executable needs to be in PATH" but I literally set it in the PATH using export path=$PATH:/usr/local/bin/geckodriver.exe, my echo $PATH returns:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/bin/geckodriver.exe

So it clearly is there!

edit: geckodriver.exe seems to be a windows thing so I removed it and as /usr/local/bin is already included in PATH on default I only need to execute

driver = webdriver.Firefox()

But then I receive a similiar error: "[Errno 8] Exec format error: 'geckodriver'" Which usually means my system is not compatible but I downloaded the linux32 version from here (https://github.com/mozilla/geckodriver/releases) and extracted it to /usr/local/bin ... raspberry pi 3 should be 32 bit!

3.

import subprocess
import os
subprocess.call(["x-www-browser", "localhost:3000", "--no-sandbox"])
//later on when PIR sensor toggles display OFF 
//os.system("taskkill /f /im  /usr/bin/firefox.exe")

problem here: This does indeed open my chromium browser (even though that is not my default browser!) but it does not navigate to any url and an annoying error warning pops up in the top.

Method 4 would probably be something like executing a javascript file that contains window.location.reload(true) but I did not try that yet since all the answers to this question on the web are super complicated and require downloading lots of libraries and learning syntax of these..

Method 5 could be creating an empty file on detection while my javascript is also checking on an infinite loop if any new files got added and then executes window.location.reload(true) ... which would be... super inefficient

All in all I would prefer method 2 (selenium) to work because there I could also just call driver.refresh() that would make sure my browser also stays in fullscreen mode (F11) since you don't want to see a browser bar when looking into a smart mirror...

My setup is a raspberry pi 3 b+ running the raspbian lite OS (linux distribution), firefox-esr 60.9.0, selenium 3.141, python3 and geckodriver 26 (linux 32 bit)..Please help! Do you spot any mistakes? Have you ever achieved something similiar? Do you get any extra genius ideas how I could accomplish that? I really just want to refresh a goddamn browser page - I could cry...


Viewing all articles
Browse latest Browse all 99411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>