Skip to content

Commit

Permalink
test: fix linter by formatting selenium.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseInfinity committed Oct 25, 2023
1 parent 8e88271 commit 2335525
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions chromegpt/tools/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}"

Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 2335525

Please sign in to comment.