{
  "id": "python/pytest-selenium-stale-element",
  "signature": "selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document",
  "signature_zh": "selenium.common.exceptions.StaleElementReferenceException: 消息: 陈旧元素引用: 元素未附加到页面文档",
  "regex": "selenium\\.common\\.exceptions\\.StaleElementReferenceException:\\ Message:\\ stale\\ element\\ reference:\\ element\\ is\\ not\\ attached\\ to\\ the\\ page\\ document",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test holds a WebElement reference obtained before a DOM re-render (navigation, AJAX update, React key change); the underlying node was replaced.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试持有在 DOM 重新渲染（导航、AJAX 更新、React key 变化）之前获取的 WebElement 引用；底层节点已被替换。",
  "versions": [
    {
      "version": "4.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The element may still be replaced after the sleep; timing is not the root cause and the test becomes slow and flaky.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Swallowing the exception skips the assertion entirely, producing false positives and hiding real UI regressions.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def click_row(driver, row_text):\n    for _ in range(5):\n        try:\n            row = driver.find_element(By.XPATH, f\"//tr[td[text()='{row_text}']]\")\n            row.find_element(By.CSS_SELECTOR, 'button.delete').click()\n            return\n        except StaleElementReferenceException:\n            continue\n    raise AssertionError('element never stabilized')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "from selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\nfrom selenium.webdriver.common.by import By\n\nel = WebDriverWait(driver, 10).until(\n    EC.element_to_be_clickable((By.ID, 'submit'))\n)\nel.click()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}