Search code examples
pythonselenium-webdriverselenium-chromedriver

Selenium Chrome driver does not recognize certificates, but manual browsing works fine


I am encountering an issue with Selenium and Chrome where the browser does not recognize certificates when using the Selenium Chrome driver.
Strangely, when I manually open Google Chrome and visit the same websites, everything works fine.
Below is the code I'm using:

from seleniumwire import webdriver
from webdriver_manager.chrome import ChromeDriverManager

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('--ignore-certificate-errors')

driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=chromeOptions)
driver.get("https://www.google.com")

However, when I run the code, I get the following result:

enter image description here

Could someone please help me understand what I might be doing wrong?


Solution

  • Since you are using selenium wire You need to install the certificate in your local machine You can also get the certificate by running the following command

    python -m seleniumwire extractcert
    

    or

    python3 -m seleniumwire extractcert
    

    You can also get the file from below link also jut copy paste it to a file and name it "ca.crt"

    Cert

    Once you have the ".crt" file downloaded you have to import the certificate. In MAC Open Keychain Access and them import items and them import the .crt file , then search for "Selenium Wire CA" cert , double click , expand the trust section and select Always trust, after this you should not see Not Secured in chrome anymore

    For windows Launch MMC (mmc.exe) -> Choose File > Add/Remove Snap-ins -> Choose Certificates, then choose Add -> Choose My user account -> Choose Add again and this time select Computer Account -> Move the new certificate from the Certificates-Current User -> Trusted Root Certification Authorities into Certificates (Local Computer) -> Trusted Root Certification Authorities.

    Reference