mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-07 19:45:27 +00:00
feat : better form handling
This commit is contained in:
parent
f69ceb5025
commit
7890b4b3ca
@ -1,3 +1,4 @@
|
|||||||
|
import platform, os
|
||||||
|
|
||||||
from sources.utility import pretty_print, animate_thinking
|
from sources.utility import pretty_print, animate_thinking
|
||||||
from sources.agents.agent import Agent, executorResult
|
from sources.agents.agent import Agent, executorResult
|
||||||
@ -20,6 +21,7 @@ class CoderAgent(Agent):
|
|||||||
"go": GoInterpreter(),
|
"go": GoInterpreter(),
|
||||||
"file_finder": FileFinder()
|
"file_finder": FileFinder()
|
||||||
}
|
}
|
||||||
|
self.work_dir = self.tools["file_finder"].get_work_dir()
|
||||||
self.role = {
|
self.role = {
|
||||||
"en": "code",
|
"en": "code",
|
||||||
"fr": "codage",
|
"fr": "codage",
|
||||||
@ -27,10 +29,20 @@ class CoderAgent(Agent):
|
|||||||
}
|
}
|
||||||
self.type = "code_agent"
|
self.type = "code_agent"
|
||||||
|
|
||||||
|
|
||||||
|
def add_sys_info_prompt(self, prompt):
|
||||||
|
"""Add system information to the prompt."""
|
||||||
|
info = f"System Info:\n" \
|
||||||
|
f"OS: {platform.system()} {platform.release()}\n" \
|
||||||
|
f"Python Version: {platform.python_version()}\n" \
|
||||||
|
f"\nYou must work in directory: {self.work_dir}"
|
||||||
|
return f"{prompt}\n\n{info}"
|
||||||
|
|
||||||
def process(self, prompt, speech_module) -> str:
|
def process(self, prompt, speech_module) -> str:
|
||||||
answer = ""
|
answer = ""
|
||||||
attempt = 0
|
attempt = 0
|
||||||
max_attempts = 3
|
max_attempts = 4
|
||||||
|
prompt = self.add_sys_info_prompt(prompt)
|
||||||
self.memory.push('user', prompt)
|
self.memory.push('user', prompt)
|
||||||
clarify_trigger = "REQUEST_CLARIFICATION"
|
clarify_trigger = "REQUEST_CLARIFICATION"
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ class Browser:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def find_all_inputs(self, timeout=4):
|
def find_all_inputs(self, timeout=3):
|
||||||
WebDriverWait(self.driver, timeout).until(
|
WebDriverWait(self.driver, timeout).until(
|
||||||
EC.presence_of_element_located((By.TAG_NAME, "body"))
|
EC.presence_of_element_located((By.TAG_NAME, "body"))
|
||||||
)
|
)
|
||||||
@ -291,14 +291,17 @@ class Browser:
|
|||||||
continue
|
continue
|
||||||
input_name = element["text"] or element["id"] or input_type
|
input_name = element["text"] or element["id"] or input_type
|
||||||
if input_type == "checkbox" or input_type == "radio":
|
if input_type == "checkbox" or input_type == "radio":
|
||||||
|
try:
|
||||||
checked_status = "checked" if element.is_selected() else "unchecked"
|
checked_status = "checked" if element.is_selected() else "unchecked"
|
||||||
|
except Exception as e:
|
||||||
|
continue
|
||||||
form_strings.append(f"[{input_name}]({checked_status})")
|
form_strings.append(f"[{input_name}]({checked_status})")
|
||||||
else:
|
else:
|
||||||
form_strings.append(f"[{input_name}]("")")
|
form_strings.append(f"[{input_name}]("")")
|
||||||
return form_strings
|
return form_strings
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return [f"Error extracting form inputs."]
|
raise e
|
||||||
|
|
||||||
def get_buttons_xpath(self) -> List[str]:
|
def get_buttons_xpath(self) -> List[str]:
|
||||||
"""
|
"""
|
||||||
@ -312,13 +315,14 @@ class Browser:
|
|||||||
continue
|
continue
|
||||||
text = (button.text or button.get_attribute("value") or "").lower().replace(' ', '')
|
text = (button.text or button.get_attribute("value") or "").lower().replace(' ', '')
|
||||||
xpath = f"(//button | //input[@type='submit'])[{i + 1}]"
|
xpath = f"(//button | //input[@type='submit'])[{i + 1}]"
|
||||||
if "login" in text or "sign" in text or "register":
|
|
||||||
result.append((text, xpath))
|
result.append((text, xpath))
|
||||||
result.sort(key=lambda x: len(x[0]))
|
result.sort(key=lambda x: len(x[0]))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def find_and_click_submission(self, timeout: int = 10) -> bool:
|
def find_and_click_submission(self, timeout: int = 10) -> bool:
|
||||||
possible_submissions = ["login", "submit", "register"]
|
possible_submissions = ["login", "submit", "register", "calculate", "login", "submit", "register", "calculate", "save", "send",
|
||||||
|
"continue", "apply", "ok", "confirm", "next", "proceed", "accept", "agree", "yes", "no", "cancel",
|
||||||
|
"close", "done", "finish", "start", "calculate"]
|
||||||
for submission in possible_submissions:
|
for submission in possible_submissions:
|
||||||
if self.find_and_click_btn(submission, timeout):
|
if self.find_and_click_btn(submission, timeout):
|
||||||
return True
|
return True
|
||||||
@ -392,6 +396,7 @@ class Browser:
|
|||||||
element.click()
|
element.click()
|
||||||
self.logger.info(f"Set {name} to {value}")
|
self.logger.info(f"Set {name} to {value}")
|
||||||
else:
|
else:
|
||||||
|
element.clear()
|
||||||
element.send_keys(value)
|
element.send_keys(value)
|
||||||
self.logger.info(f"Filled {name} with {value}")
|
self.logger.info(f"Filled {name} with {value}")
|
||||||
return True
|
return True
|
||||||
@ -443,13 +448,12 @@ if __name__ == "__main__":
|
|||||||
browser = Browser(driver, anticaptcha_manual_install=True)
|
browser = Browser(driver, anticaptcha_manual_install=True)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
print("AntiCaptcha Test")
|
print("AntiCaptcha / Form Test")
|
||||||
browser.go_to("https://www.google.com/recaptcha/api2/demo")
|
browser.go_to("https://www.google.com/recaptcha/api2/demo")
|
||||||
|
#browser.go_to("https://practicetestautomation.com/practice-test-login/")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
print("Form Test:")
|
|
||||||
browser.go_to("https://practicetestautomation.com/practice-test-login/")
|
|
||||||
inputs = browser.get_form_inputs()
|
inputs = browser.get_form_inputs()
|
||||||
inputs = ['[username](student)', f'[password](Password123)', '[appOtp]()', '[backupOtp]()']
|
inputs = ['[input1](Martin)', f'[input2](Test)', '[input3](test@gmail.com)']
|
||||||
browser.fill_form_inputs(inputs)
|
browser.fill_form_inputs(inputs)
|
||||||
browser.find_and_click_submission()
|
browser.find_and_click_submission()
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user