fix(positions): sync latest scraper fixes from main repository
All checks were successful
Build and Push Docker Image / build (push) Successful in 36s

This commit is contained in:
2026-04-24 21:34:38 +00:00
parent 429a2832fd
commit a05ba3b8a8
4 changed files with 385 additions and 97 deletions

View File

@@ -1160,7 +1160,7 @@ async def switch_account_via_api(page, account_number: str, debug: bool = False)
return False
async def switch_account_on_page(page, account_query: Optional[str], debug: bool = False) -> bool:
async def switch_account_on_page(page, account_query: Optional[str], context=None, debug: bool = False) -> bool:
"""Attempt to switch account using the page-level selector given a query like '604' or 'Joint'."""
if not account_query:
return False
@@ -1176,7 +1176,7 @@ async def switch_account_on_page(page, account_query: Optional[str], debug: bool
if 'accounts/history' not in page.url:
if debug:
print("DEBUG: Not on history page, navigating...")
await goto_history(page, debug=debug)
await goto_history(page, context=context, debug=debug)
# ENHANCED DEBUGGING: Take screenshot before attempting switch
if debug:
@@ -1221,8 +1221,11 @@ async def switch_account_on_page(page, account_query: Optional[str], debug: bool
for (const button of elements) {
if (button.offsetParent !== null && button.offsetWidth > 0 && button.offsetHeight > 0) {
try {
button.scrollIntoView({ behavior: 'smooth', block: 'center' });
button.click();
button.scrollIntoView({ behavior: 'auto', block: 'center' });
// Use a slight delay before clicking to avoid context destruction issues
setTimeout(() => {
try { button.click(); } catch(e) {}
}, 10);
return { success: true, selector: selector, text: (button.textContent || '').trim().substring(0, 50) };
} catch (e) {
continue;
@@ -2023,7 +2026,42 @@ async def switch_account_on_page(page, account_query: Optional[str], debug: bool
if debug:
print(f"DEBUG: Keyboard navigation failed: {e}")
if not account_clicked and debug:
if not account_clicked:
if debug:
print(f"DEBUG: All primary switch methods failed for {account_query}, attempting Summary page fallback...")
try:
# Go to summary page if not already there
if "accounts/summary" not in page.url:
await page.goto("https://client.schwab.com/app/accounts/summary/#/")
await page.wait_for_timeout(5000)
# Find the row for this account in the summary table and click its link
clicked_summary = await page.evaluate("""
(query) => {
const rows = Array.from(document.querySelectorAll('sdps-table-row, tr'));
const targetRow = rows.find(r => r.innerText.includes(query) || r.textContent.includes(query));
if (targetRow) {
const link = targetRow.querySelector('a.acctNavigate-button-link');
if (link) {
link.click();
return true;
}
}
return false;
}
""", account_query)
if clicked_summary:
if debug:
print(f"DEBUG: Successfully clicked account {account_query} on summary page")
await page.wait_for_timeout(5000)
return True
except Exception as summary_err:
if debug:
print(f"DEBUG: Summary page fallback failed: {summary_err}")
if debug:
print(f"DEBUG: Could not find and click/select target account: {target_account['label']}")
print(f"DEBUG: Target account details: {target_account}")