1

I am trying to connect securely to a website that has a valid SSL certificate. However, when I connect using Selenium the Chrome browser says the connection is insecure. If I click on the "Not secure" flag in the url bar, it says "Your connection to this site is not secure." If I click on the link below this which says Certificate (Invalid) this opens up a new window with details on the certificate which say "This certificate is valid." How am I supposed to understand this nonsensical discrepancy?

I can connect to some sites securely. For example, connecting to https://www.google.com does not cause the same problem. The site I am having problems with is using a certificate from LetsEncrypt. I really don't know whether this problem is has anything to do with that but what's wrong with the cert or why does Selenium have a problem with it?

Incidentally, I can get Selenium to ignore the error using the "ignore-certificate-errors" flag in the driver options. But this leads to problems down the road when I try to authenticate. So it's not a solution.

The code I am using is basically this with the url and path replaced:

driver = webdriver.Chrome('/path/chromedriver')
driver.get('https://xxx')
julian
  • 368
  • 3
  • 12
  • 1
    Check the cert by using this site: https://www.ssllabs.com/ssltest/ – pcalkins May 10 '21 at 21:05
  • Thanks for the suggestion. The cert passed with an A rating. – julian May 10 '21 at 21:47
  • this is pretty odd... include your webdriver initialization code up to the get() that's causing the issue. It almost sounds like a caching problem, but not sure why you'd have a cached cert in a Selenium session unless you're using an existing profile. – pcalkins May 10 '21 at 22:09
  • I added a code snippet. It's standard stuff. – julian May 10 '21 at 22:58

2 Answers2

0

I discovered the problem was in the url I was passing to the chrome driver. I had mistakenly included www in the url which did not match the url in the ssl cert. I realized how this could cause problems after reading Chrome says SSL invalid, but certificate is valid which covers the maddening scenario when your chrome browser tells you the SSL cert is both valid and invalid at the same time.

julian
  • 368
  • 3
  • 12
0

what works for me in selenium 4.11 is this. pass in your url where i have mine.

options = selenium.webdriver.chrome.options.Options()
options.add_argument('ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors=yes')

chrome_browser = webdriver.Chrome(options=options)
chrome_browser.get('https://demo.seleniumeasy.com/basic-first-form- 
demo.html')