From 4681fe8b2d9dd54148c9cc228f6ec2c251cbcd29 Mon Sep 17 00:00:00 2001
From: tdorssers <tim.dorssers@xs4all.nl>
Date: Sun, 12 Sep 2021 14:08:53 +0200
Subject: [PATCH] Fix uncaught exception

---
 gui.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gui.py b/gui.py
index 772606c..f15729f 100644
--- a/gui.py
+++ b/gui.py
@@ -14,6 +14,7 @@
     from selenium import webdriver
     from selenium.webdriver.support import expected_conditions as EC
     from selenium.webdriver.support.ui import WebDriverWait
+    from selenium.common.exceptions import WebDriverException
 except ImportError:
     webdriver = None
 try:
@@ -500,9 +501,9 @@ def show_dialog():
 
     def login(self):
         """ Display login dialog and start new thread to get vehicle list """
-        result = askstring('Login', 'Use browser to login.\nPage Not Found '
-                           'will be shown at success.\n\nEmail:',
-                           initialvalue=self.email)
+        prompt = 'Email:' if webdriver else 'Use browser to login.\n' \
+                 'Page Not Found will be shown at success.\n\nEmail:'
+        result = askstring('Login', prompt, initialvalue=self.email)
         if result:
             self.email = result
             self.status.text('Logging in...')
@@ -976,8 +977,9 @@ def run(self):
         try:
             self.tesla.fetch_token()
             self.vehicles = self.tesla.vehicle_list()
-        except (teslapy.RequestException, teslapy.OAuth2Error, ValueError) as e:
-            self.exception = e
+        except (teslapy.RequestException, teslapy.OAuth2Error,
+                WebDriverException) as e:
+            self.exception = str(e).replace('\n', '')
 
 class StatusThread(threading.Thread):
     """ Retrieve vehicle status summary """