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
• 770 points
11,781 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 28, 2018 in Selenium by nsv999
• 5,500 points
27,378 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,150 points
902 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,150 points
4,260 views
0 votes
2 answers

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,500 points
13,677 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,144 views
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,910 points
7,222 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,876 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
10,816 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP