File tree Expand file tree Collapse file tree
browser_utils/page_controller_modules
tests/browser_utils/page_controller_modules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -444,6 +444,23 @@ async def _control_thinking_mode_toggle(
444444
445445 try :
446446 toggle_locator = self .page .locator (toggle_selector )
447+
448+ # First check if element exists at all (for non-thinking models like gemini-2.0-flash)
449+ element_count = await toggle_locator .count ()
450+ if element_count == 0 :
451+ if not should_be_enabled :
452+ # Trying to disable on a model without thinking toggle - just skip
453+ self .logger .info (
454+ " 主思考开关不存在(当前模型不支持思考模式),无需关闭。"
455+ )
456+ return True
457+ else :
458+ # User wants to enable but toggle doesn't exist
459+ self .logger .warning (
460+ " 主思考开关不存在(当前模型可能不支持思考模式),无法开启。"
461+ )
462+ return False
463+
447464 await expect_async (toggle_locator ).to_be_visible (timeout = 5000 )
448465 try :
449466 await toggle_locator .scroll_into_view_if_needed ()
@@ -537,6 +554,23 @@ async def _control_thinking_budget_toggle(
537554
538555 try :
539556 toggle_locator = self .page .locator (toggle_selector )
557+
558+ # First check if element exists at all (for non-thinking models)
559+ element_count = await toggle_locator .count ()
560+ if element_count == 0 :
561+ if not should_be_checked :
562+ # Trying to disable on a model without budget toggle - just skip
563+ self .logger .info (
564+ " 思考预算开关不存在(当前模型不支持),无需禁用。"
565+ )
566+ return
567+ else :
568+ # User wants to enable but toggle doesn't exist
569+ self .logger .warning (
570+ " 思考预算开关不存在(当前模型可能不支持),无法启用。"
571+ )
572+ return
573+
540574 await expect_async (toggle_locator ).to_be_visible (timeout = 5000 )
541575 try :
542576 await toggle_locator .scroll_into_view_if_needed ()
Original file line number Diff line number Diff line change @@ -628,6 +628,7 @@ async def test_set_thinking_level_errors(mock_controller):
628628async def test_control_thinking_mode_toggle_fallback (mock_controller ):
629629 # Test fallback to aria-label based toggle click
630630 toggle = MagicMock ()
631+ toggle .count = AsyncMock (return_value = 1 ) # Element exists
631632 toggle .get_attribute = AsyncMock (return_value = "false" )
632633 toggle .click = AsyncMock (side_effect = Exception ("Click failed" ))
633634
@@ -666,6 +667,7 @@ def locator_side_effect(selector):
666667async def test_control_thinking_budget_toggle_fallback (mock_controller ):
667668 # Test fallback to aria-label based toggle click
668669 toggle = MagicMock ()
670+ toggle .count = AsyncMock (return_value = 1 ) # Element exists
669671 toggle .get_attribute = AsyncMock (return_value = "false" )
670672 toggle .click = AsyncMock (side_effect = Exception ("Click failed" ))
671673
You can’t perform that action at this time.
0 commit comments