at the moment I'm getting this output of a crontab exception to my email:
Traceback (most recent call last):
File "test.py", line 137, in test
self.product_to_cart()
File "test.py", line 18, in product_to_cart
atc_btn = self.driver.find_element_by_id('product-addtocart-button')
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="product-addtocart-button"]"}
(Session info: headless chrome=77.0.3865.90)
Is it possible to modify the output so that people who ain't working with selenium know what's going on when they get this kind of crontab mail output? Like some more human readable output..
I've already tried to use a normal print and raise Exception(message) but it doesn't show up in the email
Note: It's not about solving the error message itself.. just the visualization of the output(!)
Thanks!
It is not a "crontab exception", it is a Python exception that cron just passed along. Cron just sends you the script's output. The output of your script is an uncaught exception message. Catch the exception and print what you want the mail to say instead.
try:
do_something_dangerous()
except selenium.common.exceptions.NoSuchElementException as x:
print("Bad stuff happened!", file=sys.stderr)