0

我正在自动化登录和下载数据过程。在我的最后一步:单击“导出”,然后下载 .csv 文件。我遇到了错误:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=86.0.4240.111)

我尝试了很多方法如下,但我无法修复它。'''

driver.find_element_by_xpath('...').click()
driver.find_element_by_xpath('...').click()
driver.find_element_by_css_selector('...').click()

options = Options()
options.add_experimental_option("prefs", {
  "download.default_directory": r"C:\Users\yhu\Downloads",
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True
})

特定的 HTML 元素:

<a onclick="return onGridExport(this);" id="ctl00_ctl39_g_c2f29a2f_3d77_43a2_b3ae_ad4098b04506_GridExport" tabindex="43" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl39$g_c2f29a2f_3d77_43a2_b3ae_ad4098b04506$GridExport&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">Export</a>
4

0 回答 0