How can I handle certificates when testing pages with Selenium?

0 votes

I'm using Selenium for launching the browser for tests. How can I handle webpages which ask the browser to accept certificates? The problem is that for different browsers, the certificate prompt is different, meaning even the elements would be different. Look below for example.

In Firefox, the website asks to accept certificates like this:

In IE, it looks like this:

And in Google Chrome, it looks like this:

So how can I automate the acceptance of any website's certificate when I launch any browser? I'm writing the Selenium code in Python.

May 8, 2018 in Selenium by eLiJha
• 760 points
6,163 views

1 answer to this question.

0 votes

In Firefox, you should set 'accept_untrusted_certs' of FirefoxProfile() option to True. Code:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True

driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://cacert.org/')

driver.close()

In case of Chrome, you have to add --ignore-certificate-errors to ChromeOptions() argument:

from selenium import webdriver

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

driver = webdriver.Chrome(chrome_options=options)
driver.get('https://cacert.org/')

driver.close()

And with Internet Explorer, you have to set acceptSslCerts desired capability:

from selenium import webdriver

capabilities = webdriver.DesiredCapabilities().INTERNETEXPLORER
capabilities['acceptSslCerts'] = True

driver = webdriver.Ie(capabilities=capabilities)
driver.get('https://cacert.org/')

driver.close()

In fact we can use desired capabilities for pretty much every browser. Look at the Desired Capabilities documentation for how it is done: https://code.google.com/p/selenium/wiki/DesiredCapabilities

answered May 8, 2018 by king_kenny
• 3,710 points

Related Questions In Selenium

+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
13,496 views
0 votes
1 answer
0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9, 2019 in Selenium by Anvi
• 14,030 points
164 views
0 votes
1 answer

How can I use HTML Unit Driver as a headless browser with Selenium?

Hello @Nishant, follow these steps to use ...READ MORE

answered May 17, 2019 in Selenium by Anvi
• 14,030 points
1,285 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
2,541 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
2,025 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
2,108 views
0 votes
1 answer

How do i click on <input type=file> on any browser if i'm testing with Selenium Webdriver?

Does not matter which OS or which ...READ MORE

answered Apr 29, 2018 in Selenium by king_kenny
• 3,710 points
5,495 views
0 votes
1 answer