You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Selenium证书解析错误?Python点击元素代码求助

解决Selenium点击元素时的证书解析错误问题

你遇到的ERROR: Couldn't read tbsCertificate as SEQUENCE, ERROR: Failed parsing Certificate错误,本质是Chrome浏览器加载目标网站时的SSL证书验证问题,和元素定位逻辑关联不大。以下是具体解决方案:

1. 禁用Chrome的SSL证书验证

修改Chrome启动参数,让浏览器忽略证书错误:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://nmit.ac.in'

# 添加忽略证书错误的启动参数
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')

driver = webdriver.Chrome(options=options)

driver.get(url)

try:
    # 等待元素可点击(而非仅存在),确保元素能交互
    element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.LINK_TEXT, "Parent Portal"))
    )
    element.click()  # 直接使用等待到的元素点击,避免重复查找
except Exception as e:
    print(f"操作失败: {str(e)}")
finally:
    driver.quit()  # 结束后关闭浏览器,避免进程残留

2. 优化原有代码逻辑

  • 将presence_of_element_located替换为element_to_be_clickable:点击操作需要元素处于可交互状态,仅判断存在无法保证点击有效
  • 等待到元素后直接点击,避免重复调用find_element,减少不必要的错误点
  • 捕获异常时输出具体错误信息,便于后续排查

3. 检查Chrome驱动与浏览器版本匹配

如果上述方法无效,确认你的Chrome驱动版本与本地Chrome浏览器版本完全一致——版本不匹配会引发各类异常,包括SSL相关的解析错误。

内容的提问来源于stack exchange,提问作者KrevoL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 13:10:28