Skip to content

Commit 63bc4d6

Browse files
author
maebahesioru
committed
fix: improve page stability and parameter setting reliability
- _verify_chat_cleared: fallback to textarea visibility when zero_state not visible, ensuring page is ready before proceeding - _ensure_tools_panel_expanded: skip if button not found (new UI layout) - _adjust_google_search: skip if toggle not found - _set_parameter_with_retry: add blur event + Tab key, use triple_click for reliable field clearing before fill - submit_prompt: increase textarea locator timeout 5s -> 15s - click_element for Submit Button: timeout 2s -> 10s
1 parent dba0b55 commit 63bc4d6

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/browser/page_controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ async def _adjust_google_search(self, request_params: Dict[str, Any], check_clie
376376
for attempt in range(1, max_retries + 1):
377377
try:
378378
toggle_locator = self.page.locator(toggle_selector)
379+
if await toggle_locator.count() == 0:
380+
self.logger.debug(f'[{self.req_id}] Google Search 开关不存在,跳过。')
381+
return
379382
await expect_async(toggle_locator).to_be_visible(timeout=5000)
380383
await self._check_disconnect(check_client_disconnected, 'Google Search 開關 - 元素可見後')
381384
is_checked_str = await toggle_locator.get_attribute('aria-checked')
@@ -467,6 +470,9 @@ async def _ensure_tools_panel_expanded(self, check_client_disconnected: Callable
467470
for attempt in range(1, max_retries + 1):
468471
try:
469472
collapse_tools_locator = self.page.locator('button[aria-label="Expand or collapse tools"]')
473+
if await collapse_tools_locator.count() == 0:
474+
self.logger.info(f'[{self.req_id}] 工具面板展开按钮不存在,跳过。')
475+
return
470476
await expect_async(collapse_tools_locator).to_be_visible(timeout=5000)
471477
grandparent_locator = collapse_tools_locator.locator('xpath=../..')
472478
class_string = await grandparent_locator.get_attribute('class', timeout=3000)
@@ -581,23 +587,25 @@ def is_equal(val1, val2):
581587

582588
if attempt == 0:
583589
strategy_name = "JS Injection"
584-
await locator.evaluate('(el, val) => { el.value = val; el.dispatchEvent(new Event("input", {bubbles: true})); el.dispatchEvent(new Event("change", {bubbles: true})); }', str(target_value))
590+
await locator.evaluate('(el, val) => { el.value = val; el.dispatchEvent(new Event("input", {bubbles: true})); el.dispatchEvent(new Event("change", {bubbles: true})); el.dispatchEvent(new Event("blur", {bubbles: true})); }', str(target_value))
585591
await asyncio.sleep(DELAY_AFTER_FILL)
586-
await locator.press('Enter')
592+
await locator.press('Tab')
587593
elif attempt == 1:
588594
strategy_name = "Standard Fill"
589595
await locator.focus()
596+
await locator.triple_click()
590597
await locator.fill(str(target_value))
598+
await locator.press('Tab')
599+
await asyncio.sleep(DELAY_AFTER_FILL)
591600
await locator.dispatch_event('change')
592-
await locator.press('Enter')
593601
else:
594602
strategy_name = "Select & Type"
595603
await locator.focus()
596604
await locator.select_text()
597605
await locator.press('Backspace')
598606
await asyncio.sleep(SLEEP_TICK)
599607
await locator.type(str(target_value), delay=50)
600-
await locator.press('Enter')
608+
await locator.press('Tab')
601609

602610
await asyncio.sleep(SLEEP_LONG)
603611

@@ -1011,7 +1019,7 @@ async def _paste_images_via_event(self, images: List[Dict[str, str]], target_loc
10111019

10121020
async def submit_prompt(self, prompt: str, image_list: List, check_client_disconnected: Callable):
10131021
self.logger.info(f'[{self.req_id}] 📤 提交提示 ({len(prompt)} chars)...')
1014-
prompt_textarea_locator, matched_selector = await get_first_visible_locator(self.page, PROMPT_TEXTAREA_SELECTORS, timeout=5000)
1022+
prompt_textarea_locator, matched_selector = await get_first_visible_locator(self.page, PROMPT_TEXTAREA_SELECTORS, timeout=15000)
10151023
if not prompt_textarea_locator:
10161024
self.logger.warning(f'[{self.req_id}] 未找到输入框,尝试默认选择器')
10171025
prompt_textarea_locator = self.page.locator(PROMPT_TEXTAREA_SELECTOR)

0 commit comments

Comments
 (0)