From 2335525a78de7ee03b8341cfa7476d974adc547c Mon Sep 17 00:00:00 2001 From: Stefan Ayala Date: Tue, 24 Oct 2023 18:02:17 -0700 Subject: [PATCH] test: fix linter by formatting selenium.py --- chromegpt/tools/selenium.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/chromegpt/tools/selenium.py b/chromegpt/tools/selenium.py index e8d320a..f32cc50 100644 --- a/chromegpt/tools/selenium.py +++ b/chromegpt/tools/selenium.py @@ -83,8 +83,7 @@ def google_search(self, query: str) -> str: results = self._get_google_search_results() return ( "Which url would you like to goto? Provide the full url starting with http" - " or https to goto: " - + json.dumps(results) + " or https to goto: " + json.dumps(results) ) def _get_google_search_results(self) -> List[Dict[str, Any]]: @@ -123,10 +122,11 @@ def describe_website(self, url: Optional[str] = None) -> str: ) # Let driver wait for website to load - WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "body"))) + WebDriverWait(self.driver, 10).until( + EC.presence_of_element_located((By.TAG_NAME, "body")) + ) time.sleep(5) - try: # Extract main content main_content = self._get_website_main_content() @@ -238,7 +238,9 @@ def _find_form_fields(self, url: Optional[str] = None) -> str: self.driver.get(url) # Let driver wait for website to load time.sleep(5) - WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "body"))) + WebDriverWait(self.driver, 10).until( + EC.presence_of_element_located((By.TAG_NAME, "body")) + ) except WebDriverException as e: return f"Error loading url {url}, message: {e.msg}" @@ -281,7 +283,9 @@ def fill_out_form(self, form_input: Optional[str] = None, **kwargs: Any) -> str: else: form_input_dict = kwargs # use kwargs if form_input is not a valid string - assert isinstance(form_input_dict, dict), "form_input should be a dictionary at this point." + assert isinstance( + form_input_dict, dict + ), "form_input should be a dictionary at this point." MAX_RETRIES = 3 @@ -294,10 +298,17 @@ def fill_out_form(self, form_input: Optional[str] = None, **kwargs: Any) -> str: # Use explicit wait to find the element time.sleep(1) element = WebDriverWait(self.driver, 10).until( - EC.presence_of_element_located((By.XPATH, f"//textarea[@name='{key}'] | //input[@name='{key}']")) + EC.presence_of_element_located( + ( + By.XPATH, + f"//textarea[@name='{key}'] | //input[@name='{key}']", + ) + ) ) # Scroll the element into view - self.driver.execute_script("arguments[0].scrollIntoView();", element) + self.driver.execute_script( + "arguments[0].scrollIntoView();", element + ) # Clear the input field element.send_keys(Keys.CONTROL + "a") @@ -317,7 +328,6 @@ def fill_out_form(self, form_input: Optional[str] = None, **kwargs: Any) -> str: except WebDriverException as e: return f"Error filling out form with input {form_input}, message: {e.msg}" - if not filled_element: return ( f"Cannot find form with input: {form_input.keys()}." # type: ignore