Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Fix scroll to text
magmueller1870a6b7b8df
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 5627264dd..5af109c26 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -233,18 +233,27 @@ class Controller:async def scroll_to_text(text: str, browser: BrowserContext): # type: ignorepage = await browser.get_current_page()try:- # Use Playwright's built-in text content selector- element = page.get_by_text(text, exact=False)-- # Check if element exists and scroll to it- if await element.count() > 0:- await element.scroll_into_view_if_needed()- await asyncio.sleep(0.5) # Wait for scroll to complete- msg = f'🔍 Scrolled to text: {text}'- logger.info(msg)- return ActionResult(extracted_content=msg, include_in_memory=True)-- msg = f"Text '{text}' not found on page"+ # Try different locator strategies+ locators = [+ page.get_by_text(text, exact=False),+ page.locator(f'text={text}'),+ page.locator(f"//*[contains(text(), '{text}')]"),+ ]++ for locator in locators:+ try:+ # First check if element exists and is visible+ if await locator.count() > 0 and await locator.first.is_visible():+ await locator.first.scroll_into_view_if_needed()+ await asyncio.sleep(0.5) # Wait for scroll to complete+ msg = f'🔍 Scrolled to text: {text}'+ logger.info(msg)+ return ActionResult(extracted_content=msg, include_in_memory=True)+ except Exception as e:+ logger.debug(f'Locator attempt failed: {str(e)}')+ continue++ msg = f"Text '{text}' not found or not visible on page"logger.info(msg)return ActionResult(extracted_content=msg, include_in_memory=True)