【问题标题】:How to handle SSL Certificate in IE using selenium with python?如何在 IE 中使用 selenium 和 python 处理 SSL 证书?
【发布时间】:2021-05-31 12:43:20
【问题描述】:

我收到了图片中的错误。 Error_img

我尝试了以下代码来解决它。

方法一:

from selenium import webdriver

from selenium.webdriver.ie.options import Options

options = Options()

options.set_capability={"acceptInsecureCerts", True}

options.set_capability={"ignoreProtectedModeSettings":True, "ignoreZoomSetting":True}

driver = webdriver.Ie(options=options,executable_path='D:/
Project/Testing/IEDriverServer_Win32_3.150.1/IEDriverServer.exe')

driver.get(url)

options.set_capability={"ie.ensureCleanSession",True}

driver.close()

方法二:

from selenium import webdriver

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_capabilities = DesiredCapabilities.INTERNETEXPLORER.copy()

desired_capabilities['acceptInsecureCerts'] = True

driver = webdriver.Ie(capabilities=desired_capabilities,executable_path='E:/DriverServer_Win32_3.150.1/IEDriverServer.exe')

driver.get(url)

print(driver.title)

driver.close()

**无法分享网址,所以我只写了网址字

我尝试了两种代码,但都不起作用

还有其他解决方案吗?**

【问题讨论】:

  • 为什么代码不起作用?

标签: python selenium-webdriver internet-explorer ssl-certificate


【解决方案1】:

acceptInsecureCerts 功能不起作用,因为 IE 不允许接受它。您可以参考this link了解更多详细信息。

在 IE 11 中,您可以单击链接转到网页(不推荐)作为绕过 SSL 证书错误的解决方法。此链接的 ID 为“overridelink”。您可以使用 F12 开发工具找到 id。

我以这个网站:https://expired.badssl.com/为例,示例代码如下:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

url = "https://expired.badssl.com/"

ieoptions = webdriver.IeOptions()
ieoptions.ignore_protected_mode_settings = True    

driver = webdriver.Ie(executable_path='IEDriverServer.exe', options=ieoptions)
driver.get(url)
time.sleep(3)
driver.find_element_by_id('moreInfoContainer').click()
time.sleep(3)
driver.find_element_by_id('overridelink').click()

在 IE 11 中运行良好,您也可以尝试相同的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-29
    • 2011-10-23
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 2013-06-30
    • 1970-01-01
    相关资源
    最近更新 更多