workflow-use icon indicating copy to clipboard operation
workflow-use copied to clipboard

Page object missing locator() and wait_for_load_state() methods - self-healing fails

Open u007 opened this issue 10 months ago • 1 comments

Problem

When self-healing fallback triggers in workflow-use, the browser session crashes with Page object attribute errors instead of LLM-based recovery.

Error Messages

ERROR    [workflow_use.controller.utils] Selector failed: #username_BROKEN with error: 'Page' object has no attribute 'locator'
WARNING  [workflow_use.workflow.service] Timeout waiting for page to stabilize after navigation: 'Page' object has no attribute 'wait_for_load_state'

Root Cause

Two issues prevent self-healing from working:

Issue 1: Self-healing code is commented out

In workflow_use/workflow/service.py lines 691-696, the fallback logic is disabled:

# if self.fallback_to_agent:
# 	result = await self._fallback_to_agent(step_resolved, step_index, e)

The log says "Attempting fallback with agent" but then immediately raises an exception because the actual fallback code is never executed.

Issue 2: Page API incompatibility

workflow_use code calls Playwright-specific methods on the browser_use.actor.page.Page object, which is a CDP-based wrapper that doesn't implement these methods:

Location Called Method Available Method
workflow_use/controller/utils.py:25 page.locator(selector) page.get_elements_by_css_selector(selector)
workflow_use/workflow/service.py:254 page.wait_for_load_state() (none)

Steps to Reproduce

  1. Create a workflow with a valid CSS selector
  2. Copy and modify the workflow to have an invalid selector (e.g., #username → #username_BROKEN)
  3. Run the modified workflow:
    python -c "
    import asyncio
    from workflow_use.workflow.service import Workflow
    from langchain_openai import ChatOpenAI
    
    async def main():
        llm = ChatOpenAI(model='gpt-4o-mini')
        workflow = Workflow.load_from_file('path/to/broken-workflow.yaml', llm=llm)
        await workflow.run()
    
    asyncio.run(main())
    "
    
  4. Observe: Self-healing triggers ("Attempting fallback with agent") but immediately crashes with Page attribute errors

Expected Behavior

  • LLM agent should analyze the page and find the correct element
  • Workflow should complete successfully
  • Workflow file should be updated with corrected approach

Actual Behavior

  • Browser session closes immediately after fallback triggers
  • Workflow fails with 'Page' object has no attribute 'locator' error

Environment

  • Python: 3.12
  • browser-use: 0.11.4 (latest)
  • workflow-use: installed from git main branch
  • OS: macOS

Suggested Fix

Fix 1: Uncomment the fallback code

In workflow_use/workflow/service.py lines 691-696, uncomment:

if self.fallback_to_agent:
    result = await self._fallback_to_agent(step_resolved, step_index, e)
    if not result.is_successful():
        raise ValueError(f'Deterministic step {step_index + 1} ({action_name}) failed even after fallback')
else:
    raise ValueError(f'Deterministic step {step_index + 1} ({action_name}) failed: {e}')

Fix 2: Replace Playwright-specific API calls

Replace Playwright-specific API calls with browser-use's CDP-based Page API:

In workflow_use/controller/utils.py:

# Before (line 25):
locator = page.locator(try_selector)

# After:
elements = await page.get_elements_by_css_selector(try_selector)
if elements:
    locator = elements[0]  # or appropriate handling

In workflow_use/workflow/service.py:

# Before (line 254):
await page.wait_for_load_state('networkidle', timeout=10000)

# After:
# Either remove or implement CDP-based wait:
import asyncio
await asyncio.sleep(1)  # Simple delay, or implement CDP Network.loadingFinished listener

Impact

Self-healing (the main value proposition of workflow-use) is completely non-functional:

  1. The fallback code is commented out in the source
  2. Even if uncommented, Page API calls would fail

Workaround

Use run_with_no_ai mode for deterministic execution. If selectors break, manually update workflow YAML files.

u007 avatar Jan 24 '26 04:01 u007

was this intended?

u007 avatar Jan 24 '26 04:01 u007