From 5321dcc3ba48bdc098245d958385b6966d0ff502 Mon Sep 17 00:00:00 2001 From: martin legrand Date: Fri, 4 Apr 2025 14:15:29 +0200 Subject: [PATCH] fix : exception in browser --- sources/browser.py | 13 ++++++++++--- sources/interaction.py | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sources/browser.py b/sources/browser.py index 37930ba..cd94274 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -270,9 +270,13 @@ class Browser: raise e def find_all_inputs(self, timeout=3): - WebDriverWait(self.driver, timeout).until( - EC.presence_of_element_located((By.TAG_NAME, "body")) - ) + try: + WebDriverWait(self.driver, timeout).until( + EC.presence_of_element_located((By.TAG_NAME, "body")) + ) + except Exception as e: + self.logger.error(f"Error waiting for input element: {str(e)}") + return [] time.sleep(0.5) script = self.load_js("find_inputs.js") input_elements = self.driver.execute_script(script) @@ -359,6 +363,9 @@ class Browser: except TimeoutException: self.logger.warning(f"Timeout waiting for '{button_text}' button at XPath: {xpath}") return False + except Exception as e: + self.logger.error(f"Error clicking button '{button_text}' at XPath: {xpath} - {str(e)}") + return False self.logger.warning(f"No button matching '{btn_type}' found") return False diff --git a/sources/interaction.py b/sources/interaction.py index 7bf148f..2f07e81 100644 --- a/sources/interaction.py +++ b/sources/interaction.py @@ -93,6 +93,8 @@ class Interaction: self.recorder.join() self.transcriber.join() query = self.transcriber.get_transcript() + if query == "exit" or query == "goodbye": + return None return query def get_user(self) -> str: