I have a perfectly fine running python-script on my raspberry to open a website, navigate to a specific part, copy some text, save it and then compare it to something else. It works great when I start it from the terminal.
But when I have it as a cronjob, it fails with the Message "The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details." So the part, that is not working is:
from selenium import webdriver
try:
driver = webdriver.Firefox()
except Exception as e:
print(e)
As you can see I did not specify a Log-path, because I honestly don't know how. So if you can tell me that, I will gladly try to implement that and get the log.
Is there anything special you have to do, to get it started as a cronjob? I call it with
*/1 * * * * root cd /home/pi/Desktop && sudo python WebAlert.py >> /var/log/myjob.log 2>&1
From the terminal it works with python WebAlert.py
Thank you very much guys, I'm out of ideas.
EDIT
I changed some lines.
I added this:
binary = FirefoxBinary('/usr/bin/iceweasel')
and I changed the driver like this:
driver = webdriver.Firefox(executable_path=r'/usr/local/bin/geckodriver', firefox_binary=binary)
Calling it in the crontab with this
cd /home/pi/Desktop && sudo ../../../usr/bin/python3 WebAlert.py >> /var/log/mylog.log
produces the following error:
Traceback (most recent call last): File "/home/pi/Desktop/WebAlert.py", line 37, in driver = webdriver.Firefox(executable_path=r'/usr/local/bin/geckodriver', firefox_binary=binary) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in init keep_alive=True) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused