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
• 700 points
2,196 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,590 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,030 points
3,883 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 in Selenium by Anvi
• 5,680 points
10 views
0 votes
0 answers

How can I handle multiple windows Selenium?

How can I handle multiple windows in ...READ MORE

May 12 in Selenium by Shivani
7 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,030 points
51 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,130 points
410 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,130 points
40 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,590 points
2,020 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.