Skip to content

Commit

Permalink
Update selenium.py
Browse files Browse the repository at this point in the history
debug when button_text is empty
  • Loading branch information
chengxuan-xia authored Aug 3, 2023
1 parent b6e7488 commit 36e0353
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions chromegpt/tools/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,27 @@ def _get_interactable_elements(self, soup: BeautifulSoup) -> str:

interactable_texts = []
for element in interactable_elements:
button_text = find_parent_element_text(element)
button_text = prettify_text(button_text, 50)
# Detect if size is visible
if element.get("style") and "display: none" in element.get("style"):
continue
if (
button_text
and button_text not in interactable_texts
and element.is_displayed()
and element.is_enabled()
"style" in element.attrs
and "display: none" in element["style"]
):
interactable_texts.append(button_text)
continue

button_text = (
element.get("name")
or element.get("aria-label")
or element.get("value")
or element.get("id")
or find_parent_element_text(element)
)

if button_text:
button_text = prettify_text(button_text, limit=50, remove_special_char=True)
if button_text not in interactable_texts:
interactable_texts.append(button_text)

# Split up the links and the buttons
buttons_text = []
Expand Down

0 comments on commit 36e0353

Please sign in to comment.