Created
August 29, 2011 22:06
-
-
Save kra/1179537 to your computer and use it in GitHub Desktop.
Untrusted certificates and Selenium 2 in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Dev sites often don't have proper certificates - right now, I'm working with | |
expired certs with incorrect hostnames. Workarounds for using Selenium with | |
certs can be hard to find, especially for the Python webdriver (Selenium 2) | |
bindings, which have gone though many changes recently. | |
One way around this is to create a browser profile, but this has its own | |
hassles, especially if you want your test suite to work on a build box and the | |
box of any dev who wants to check it out and run it. | |
An easier way is to update the browser profile. This is how it's done for | |
Python's Selenium 2.5.0 bindings and Firefox. Other browsers will do this | |
differently. | |
The Python bindings don't enable everything explicitly, but we're just | |
writing to a Javascript file here, so we can control this without it being | |
supported. | |
""" | |
from selenium import webdriver | |
import time | |
profile = webdriver.firefox.firefox_profile.FirefoxProfile() | |
# profile has a property for this option | |
#profile.accept_untrusted_certs = 'true' | |
# this option must be set directly | |
profile.default_preferences["webdriver_assume_untrusted_issuer"] = 'false' | |
# user.js must be written before browser start | |
# breakpoint after here to view and understand that file | |
profile.update_preferences() | |
browser = webdriver.Firefox(profile) | |
browser.get('https://weirdcert.example.com') | |
time.sleep(666) # if you're displaying, enjoy not seeing the warning page here | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment